Customizing actions | 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)  Advanced-usage  Customizing actions

 Version   v1

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

  Customizing actions
- [ 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)

 Customizing actions
===================

###  On this page

1. [ Available actions ](#content-available-actions)
2. [ Which action to override ](#content-which-action-to-override)

The core behaviour of this package is split across a set of action classes, all registered in the config file. You can swap any of them out by extending the default class and pointing the config at your version.

Say you want to run some code right before the package notifies Apple that a pass has been updated. Create a class that extends `NotifyAppleOfPassUpdateAction` and override the `execute` method:

```
namespace App\Actions;

use Spatie\LaravelMobilePass\Actions\Apple\NotifyAppleOfPassUpdateAction;
use Spatie\LaravelMobilePass\Models\MobilePass;

class CustomNotifyAppleOfPassUpdateAction extends NotifyAppleOfPassUpdateAction
{
    public function execute(MobilePass $mobilePass)
    {
        // Your custom code here

        parent::execute($mobilePass);
    }
}
```

Then register your class in the `mobile-pass` config file:

```
// config/mobile-pass.php

return [
    // other keys

    'actions' => [
        // other actions

        'notify_apple_of_pass_update' => \App\Actions\CustomNotifyAppleOfPassUpdateAction::class,
    ],
];
```

Available actions
-----------------------------------------------------------------------------------------------------------

The five actions below are registered under the `actions` key in `config/mobile-pass.php`. Each one can be swapped out independently.

### register\_device

Default: `Spatie\LaravelMobilePass\Actions\Apple\RegisterDeviceAction`

Runs when Apple's device calls the register-device endpoint after the user taps Add to Wallet. It creates an `AppleMobilePassRegistration` row tying the device to the pass, then fires the `MobilePassAdded` event. Override this to hook into registrations (for audit trails, push-token tracking against another store, anti-abuse checks).

### unregister\_device

Default: `Spatie\LaravelMobilePass\Actions\Apple\UnregisterDeviceAction`

Runs when Apple's device calls the unregister-device endpoint after the user removes the pass. It deletes the matching `AppleMobilePassRegistration` rows and fires `MobilePassRemoved` for each. Override to add cleanup logic or to soft-delete instead of hard-delete.

### notify\_apple\_of\_pass\_update

Default: `Spatie\LaravelMobilePass\Actions\Apple\NotifyAppleOfPassUpdateAction`

Runs after a `MobilePass` row is updated for an Apple pass. It signs and sends an APNs push to every device registered against the pass, so each device re-fetches the updated `.pkpass`. Override to add retry logic, rate limiting, or to swap in your own APNs transport.

### notify\_google\_of\_pass\_update

Default: `Spatie\LaravelMobilePass\Actions\Google\NotifyGoogleOfPassUpdateAction`

Runs after a `MobilePass` row is updated for a Google pass. It sends a PATCH request to Google's Wallet REST API with the new object payload, and Google fans the change out to devices. Override to add extra telemetry, to patch additional fields, or to short-circuit when you know Google already has the latest state.

### handle\_google\_callback

Default: `Spatie\LaravelMobilePass\Actions\Google\HandleGoogleCallbackAction`

Runs when Google calls back to your app with a save or remove event. It resolves the `MobilePass`, stores a `GoogleMobilePassEvent` row with the raw JWT claims, then fires `MobilePassAdded` or `MobilePassRemoved`. Override to change how callbacks are recorded (say, if you want to keep them in a separate audit table) or to enrich the resolved pass before the event fires.

Which action to override
--------------------------------------------------------------------------------------------------------------------------------

As a rule of thumb:

- For side effects (logging, analytics, notifications), listen to the `MobilePassAdded` / `MobilePassRemoved` events instead. See [Events](advanced-usage/events). Events are cheaper to set up and won't break if the action's internals change.
- Override an action when the event hook isn't enough, for example when you want to change the persistence shape (different columns, different models), swap transport (custom APNs client), or reject the operation outright.

 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)
