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 →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article