laravel-greenpass is a package for the management of the European Green Pass (i.e. covid certification).
The package allows easy validation and decoding of the GreenPass. It is also suited for Laravel since it provides a
convenient custom validator for request validation.
Run the following command to install the latest applicable version of the package:
composer require robertogallea/laravel-greenpassIn your app config, add the Service Provider to the $providers array (only for Laravel 5.4 or below):
'providers' => [
...
robertogallea\LaravelGreenPass\GreenPassServiceProvider::class,
],In bootstrap/app.php, register the Service Provider
$app->register(robertogallea\LaravelGreenPass\GreenPassServiceProvider::class);By default, the underlying validation package saves the validation certificates inside
storage/app/public/green_pass_cache.
If you want to change this folder, publish the config file with the command
php artisan vendor:publish --provider="robertogallea\LaravelGreenPass\GreenPassServiceProvider" --tag="config"
and edit the certificate-storage-path key inside the config/green-pass.php file.
Make sure the chosen folder has write access!
To validate the formal correctness of a green pass, use the greenpass and greenpass_file keyword in your validation rules array. Please note that in this way you don't check that the green pass is actually valid (i.e. not expired or revoked).
public function rules()
{
return [
'greenpass_string' => 'greenpass',
//...
];
} public function rules()
{
return [
'greenpass_uploaded_file' => 'greenpass_file',
//...
];
}To perform strict validation (i.e. check actual validity) you can add the active parameter to the validator rule:
public function rules()
{
return [
'greenpass_string' => 'greenpass:active',
//...
];
} public function rules()
{
return [
'greenpass_uploaded_file' => 'greenpass_file:active',
//...
];
}A green pass can be read using the GreenPassDecoder service:
use robertogallea\LaravelGreenPass\GreenPassDecoder;
...
$greenpass = new GreenPassDecoder();
$result = $greenpass->decode('HC1:...');
var_dump($result);
// or
$result = $greenpass->decodeFile('/path/to/file');
var_dump($result);You can also use the GreenPass facade:
use robertogallea\LaravelGreenPass\GreenPassDecoder;
...
$result = \GreenPass::decode('HC1:...');
var_dump($result);
// or
$result = \GreenPass::decodeFile('/path/to/file');
var_dump($result);