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.