Laravel Packages

Create Apple Wallet Passes in Laravel

Published
Create Apple Wallet Passes in Laravel image

The Laravel passgenerator package allows you to create wallet passes compatible with Apple Wallet easily. There's not much documentation on this package, but the gist of it is creating a pass generator instance with a pass definition:

use Byte5\PassGenerator;
 
//...
$pass = new PassGenerator( 'somekindofid');
// Note: definitions can also be set from a JSON string
$pass->setPassDefinition([
"description" => "description",
"formatVersion" => 1,
"organizationName" => "organization",
"passTypeIdentifier"=> "pass.com.example.appname",
"serialNumber" => "123456",
"teamIdentifier" => "teamid",
"foregroundColor" => "rgb(99, 99, 99)",
"backgroundColor" => "rgb(212, 212, 212)",
"barcode" => [
"message" => "encodedmessageonQR",
"format" => "PKBarcodeFormatQR",
"altText" => "altextfortheQR",
"messageEncoding"=> "utf-8",
],
// ...
]);
 
$pass->addAsset(base_path('resources/assets/wallet/background.png'));
$pass->addAsset(base_path('resources/assets/wallet/thumbnail.png'));
// ...
 
$pkpass = $pass->create();

Once you have the pass instance, you can generate a response for the pass using something like the following in your controller. The pass is stored for future downloads using the configured storage disk:

return new Response($pkpass, 200, [
'Content-Transfer-Encoding' => 'binary',
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="pass.pkpass"',
'Content-length' => strlen($pkpass),
'Content-Type' => PassGenerator::getPassMimeType(),
'Pragma' => 'no-cache',
]);

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Note: the Byte5 package is a fork of thenextweb/passgenerator, which is no longer maintained according to this issue.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
NativePHP v4: Build Native iOS and Android UI in Blade image

NativePHP v4: Build Native iOS and Android UI in Blade

Read article
Laravel Lock: Distributed Locks for Models and Routes image

Laravel Lock: Distributed Locks for Models and Routes

Read article
Laravel Image Responses: Serve Resized Images From Routes image

Laravel Image Responses: Serve Resized Images From Routes

Read article
Pause All Laravel Queues During a Deploy image

Pause All Laravel Queues During a Deploy

Read article
Laravel Terminal UI for the artisan dev Command image

Laravel Terminal UI for the artisan dev Command

Read article
Pause All Queues and a New artisan dev UI in Laravel 13.25 image

Pause All Queues and a New artisan dev UI in Laravel 13.25

Read article