Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Mobile Pass Laravel Package

spatie/laravel-mobile-pass

Laravel package to generate Apple Wallet mobile passes (boarding passes, tickets, coupons, cards) with support for pushing updates to issued passes so they stay current on users’ devices. In development—don’t use in production yet.

View on GitHub
Deep Wiki
Context7

title: Associating passes with models weight: 4

This package offers methods to associate mobile passes with models. This can be useful if you want to associate a mobile pass with a user, a product, or any other model.

Preparing your model

You can associate a mobile pass with any model. First you need to add the HasMobilePasses trait to the model:

use Spatie\LaravelMobilePass\Models\Concerns\HasMobilePasses;

class User extends Model
{
    use HasMobilePasses;
}

Associating a mobile pass with a model

Then you can associate a mobile pass with the model:

$mobilePassModel = AirlinePassBuilder::make()
    ->setOrganisationName('My organisation')
    // other methods
    ->save();

User::first()->addMobilePass($mobilePassModel);

Retrieving associated mobile passes

You can retrieve all mobile passes associated with a model:

$mobilePasses = User::first()->mobilePasses;

There's also a convenience method to retrieve the first mobile pass associated with a model:

$mobilePass = User::first()->firstMobilePass();

The firstMobilePass accept a parameter to retrieve the first mobile pass of a specific type:

use Spatie\LaravelMobilePass\Enums\PassType;

$couponPass = User::first()->firstMobilePass(PassType::Coupon);

There's also a parameter filter that accepts a closure to modify the query:

$couponPass = User::first()->firstMobilePass(filter: function ($query) {
    $query->where('type', PassType::Coupon);
});
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport