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 →
Taylor disabled GitHub Issues on most Laravel open-source packages. image

Taylor disabled GitHub Issues on most Laravel open-source packages.

Read article
Exclude Vendor and Default Commands in `php artisan dev` image

Exclude Vendor and Default Commands in `php artisan dev`

Read article
The Laracon Archive image

The Laracon Archive

Read article
Group Adjacent Collection Items in Laravel with chunkBy() image

Group Adjacent Collection Items in Laravel with chunkBy()

Read article
Laravel queue:work Now Prints Why the Worker Stopped image

Laravel queue:work Now Prints Why the Worker Stopped

Read article
Sidecar Brings Statamic's Control Panel to Your Existing Markdown Sites image

Sidecar Brings Statamic's Control Panel to Your Existing Markdown Sites

Read article