Laravel Mobile Pass is a new package from Spatie (in collaboration with Dan Johnson ) that generates mobile wallet passes for Apple Wallet and Google Wallet. It covers boarding passes, event tickets, coupons, store cards, membership cards, and gift cards—and can push live updates to passes already installed on user devices.
A Single Builder API for Both Platforms
The package gives Apple and Google passes a consistent builder interface. Here's an event ticket for Apple Wallet:
使用
Spatie\LaravelMobilePass\Builders\Apple\EventTicketPassBuilder
;$mobilePass
=
EventTicketPassBuilder
::
制作
()
->
setOrganizationName
(
'Fab Four Promotions'
)
->
setSerialNumber
(
'BTL-SHEA-0042'
)
->
setDescription
(
'The Beatles at Shea Stadium'
)
->
addField
(
'事件'
,
'Beatles Live at Shea'
)
->
addField
(
'与会者'
,
'John Lennon'
,
标签
:
'姓名'
)
->
addField
(
'seat'
,
'Floor A, Row 12'
)
->
节省
();
Google Wallet follows the same pattern with one extra step—declaring a Class (a reusable template) before creating individual passes:
使用
Spatie\LaravelMobilePass\Builders\Google\EventTicketPassBuilder
;使用
Spatie\LaravelMobilePass\Enums\BarcodeType
;$mobilePass
=
EventTicketPassBuilder
::
制作
()
->
setClass
(
'beatles-shea-1965'
)
->
setAttendeeName
(
'John Lennon'
)
->
setSection
(
'Floor A'
)
->
setRow
(
'12'
)
->
setSeat
(
'24'
)
->
setBarcode
(
BarcodeType
::
Qr
,
'TICKET-12345'
)
->
节省
();
save()
返回
MobilePass
Eloquent model that implements Laravel's
Responsable
interface. Return it directly from a controller and the package serves the right format for each platform—a
.pkpass
file for Apple, a redirect to Google Wallet for Android.
Live Pass Updates
Once a pass is installed on a device, you can push changes to it. For Apple Wallet, call
updateField
在
MobilePass
模型:
$mobilePass
->
updateField
(
'seat'
,
'13A'
(英文):
You can also include a notification message when the value changes:
$mobilePass
->
updateField
(
'seat'
,
'13A'
,
changeMessage
:
'Your seat was changed to :value'
,(英文):
Google Wallet updates work by modifying the
content
array and saving:
$content
=
$mobilePass
->
内容;$content[
'googleObjectPayload'
][
'ticketHolderName'
]
=
'John Winston Lennon'
;$mobilePass
->
更新
([
'内容'
=>
$content]);
Updates are dispatched through a
PushPassUpdateJob
, which runs synchronously by default. Set
MOBILE_PASS_QUEUE_CONNECTION
in your environment to send them through a queue instead.
Multiple Pass Types
Beyond event tickets, the package includes builders for boarding passes (airline and other transit), coupons, store cards, membership cards, and gift cards. The
AirlinePassBuilder
handles flight-specific fields like departure and destination codes, passenger name, and seat:
使用
Spatie\LaravelMobilePass\Builders\Apple\AirlinePassBuilder
;使用
Spatie\LaravelMobilePass\Builders\Apple\Entities\Seat
;AirlinePassBuilder
::
制作
()
->
setOrganizationName
(
'Etihad'
)
->
setDepartureAirportCode
(
'AUH'
)
->
setDestinationAirportCode
(
'LHR'
)
->
setPassengerName
(
'Paul McCartney'
)
->
setSeats
(
Seat
::
制作
(
数字
:
'12A'
))
->
节省
();
For trains, buses, or boats, extend the
BoardingPassBuilder
and set the appropriate
TransitType
。
Try the Live Demo
Spatie has a 现场演示 where you can generate every pass type, install it on an iPhone, and trigger a live update to see the push mechanism in action. The demo source is available at spatie/laravel-mobile-pass-demo 。
查看 GitHub 存储库 for installation instructions, Apple and Google credential setup, and full documentation.





