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.
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.
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;
}
Then you can associate a mobile pass with the model:
$mobilePassModel = AirlinePassBuilder::make()
->setOrganisationName('My organisation')
// other methods
->save();
User::first()->addMobilePass($mobilePassModel);
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);
});
How can I help you explore Laravel packages today?