Updating a pass | laravel-mobile-pass | Spatie

 SPATIE

  Laravel Mobile Pass
======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-mobile-pass](https://spatie.be/docs/laravel-mobile-pass/v1)  Basic-usage  Updating a pass

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-mobile-pass/v1)

  Updating a pass
- [ Introduction ](https://spatie.be/docs/laravel-mobile-pass/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-mobile-pass/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-mobile-pass/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-mobile-pass/v1/installation-setup)
- [ Getting credentials from Apple ](https://spatie.be/docs/laravel-mobile-pass/v1/getting-credentials-from-apple)
- [ Getting credentials from Google ](https://spatie.be/docs/laravel-mobile-pass/v1/getting-credentials-from-google)
- [ Questions and issues ](https://spatie.be/docs/laravel-mobile-pass/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-mobile-pass/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-mobile-pass/v1/about-us)

Basic usage
-----------

- [ Generating your first pass ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/generating-your-first-pass)
- [ Delivering passes to users ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/handing-out-passes)
- [ Adding images ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/adding-images)
- [ Adding barcodes ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/adding-barcodes)
- [ Updating a pass ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/updating-a-pass)
- [ Retrieving mobile passes ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/retrieving-mobile-passes)
- [ Expiring passes ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/expiring-passes)

Available pass types
--------------------

- [ Introduction ](https://spatie.be/docs/laravel-mobile-pass/v1/available-pass-types/introduction)
- [ Boarding pass ](https://spatie.be/docs/laravel-mobile-pass/v1/available-pass-types/boarding-pass)
- [ Event ticket ](https://spatie.be/docs/laravel-mobile-pass/v1/available-pass-types/event-ticket)
- [ Coupon ](https://spatie.be/docs/laravel-mobile-pass/v1/available-pass-types/coupon)
- [ Loyalty card ](https://spatie.be/docs/laravel-mobile-pass/v1/available-pass-types/loyalty)
- [ Generic ](https://spatie.be/docs/laravel-mobile-pass/v1/available-pass-types/generic)

Apple Wallet
------------

- [ Field zones ](https://spatie.be/docs/laravel-mobile-pass/v1/apple-wallet/field-zones)
- [ Apple-specific methods ](https://spatie.be/docs/laravel-mobile-pass/v1/apple-wallet/apple-specific-methods)
- [ Pass relevance ](https://spatie.be/docs/laravel-mobile-pass/v1/apple-wallet/pass-relevance)
- [ NFC passes ](https://spatie.be/docs/laravel-mobile-pass/v1/apple-wallet/nfc)
- [ Attaching Wi-Fi credentials ](https://spatie.be/docs/laravel-mobile-pass/v1/apple-wallet/attaching-wifi-credentials)
- [ Storing mobile passes ](https://spatie.be/docs/laravel-mobile-pass/v1/apple-wallet/storing-mobile-passes)

Google Wallet
-------------

- [ Pass classes ](https://spatie.be/docs/laravel-mobile-pass/v1/google-wallet/pass-classes)
- [ Object methods ](https://spatie.be/docs/laravel-mobile-pass/v1/google-wallet/object-methods)
- [ Hosting pass images ](https://spatie.be/docs/laravel-mobile-pass/v1/google-wallet/hosting-images)

Advanced usage
--------------

- [ Handling errors ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/handling-errors)
- [ Customizing actions ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/customizing-actions)
- [ Customizing models ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/customizing-models)
- [ Reading stored passes ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/reading-stored-passes)
- [ Events ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/events)
- [ Testing your passes ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/testing-your-passes)

 Updating a pass
===============

###  On this page

1. [ Apple ](#content-apple)
2. [ Google ](#content-google)
3. [ Running update pushes asynchronously ](#content-running-update-pushes-asynchronously)
4. [ Customising the update action ](#content-customising-the-update-action)

A pass on someone's phone isn't frozen. Seat assignments shift, gates change, loyalty balances tick up, coupons get extended. Push those changes through the `MobilePass` model and the package handles the platform-specific mechanics for you.

You can watch this roll in live in the [demo](https://mobile-pass-demo.spatie.be). Install any pass on your iPhone, hit the "simulate change" button on the detail page, and Wallet pulls the new version within a minute.

Apple
-----------------------------------------------------------------------

For Apple passes, use `updateField` on the model. It replaces the value for the given key and saves in one call:

```
$mobilePass->updateField('seat', '13A');
```

The package notifies Apple through APNs, Apple pings the user's device, and the device fetches the new version from your server. The user sees the updated pass in Wallet without any second download or re-sent email.

If you want the user's device to display a notification when the value changes, pass a `changeMessage:`:

```
$mobilePass->updateField(
    'seat',
    '13A',
    changeMessage: 'Your seat was changed to :value',
);
```

The `:value` placeholder is replaced with the new field value when the notification renders. The `changeMessage` is stored on the field, so once you set it, Apple fires it for every future value change on that field until you overwrite it.

If you need to update several fields at once and only save once, drop down to the builder:

```
$mobilePass->builder()
    ->updateField('seat', '13A')
    ->updateField('gate', 'D68')
    ->save();
```

Google
--------------------------------------------------------------------------

Google passes don't use `updateField`. Instead, update the relevant keys on the `MobilePass` model's `content` array and save the model. The package notices the update and pushes the change to Google's Wallet API. Google takes care of notifying the device:

```
use Spatie\LaravelMobilePass\Models\MobilePass;

$mobilePass = MobilePass::find($id);

$content = $mobilePass->content;
$content['googleObjectPayload']['ticketHolderName'] = 'John Winston Lennon';

$mobilePass->update(['content' => $content]);
```

Under the hood, the package dispatches `NotifyGoogleOfPassUpdateAction`, which patches the Object on Google via the Wallet REST API. Once Google has the new state, it fans the update out to every device the pass lives on.

Running update pushes asynchronously
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

The notification to Apple (via APNs) or Google (via the Wallet REST API) goes out through a `PushPassUpdateJob`. By default that job runs synchronously in the same process, which is fine for development and low-traffic apps since errors surface immediately and no queue worker is needed.

If your app has enough traffic that those few-hundred-millisecond HTTP calls start to hurt, or you're updating passes in bulk, move the job onto a queue. Set a queue connection and every update push dispatches to the queue instead:

```
MOBILE_PASS_QUEUE_CONNECTION=redis
MOBILE_PASS_QUEUE_NAME=wallet
```

With those set, every update push goes onto the `wallet` queue on the `redis` connection. The web request returns right away and a queue worker handles the push a moment later.

`PushPassUpdateJob` is a standard Laravel `ShouldQueue` job, so the usual queue conventions apply. Tune retries, delays, and failure handling in your queue config or on the job class if you need to customise it.

Customising the update action
-----------------------------------------------------------------------------------------------------------------------------------------------

If you want to run your own code around the update push (logging, audit trails, retry policies, anything in that neighbourhood), extend either `NotifyAppleOfPassUpdateAction` or `NotifyGoogleOfPassUpdateAction` and register your class in the config. See [Customizing actions](advanced-usage/customizing-actions) for the walkthrough.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
