laravel-greenpass
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.
Installation
Run the following command to install the latest applicable version of the package:
composer require robertogallea/laravel-greenpass
Laravel
In your app config, add the Service Provider to the $providers
array (only for Laravel 5.4 or below):
'providers' => [
...
robertogallea\LaravelGreenPass\GreenPassServiceProvider::class,
],
Lumen
In bootstrap/app.php
, register the Service Provider
$app->register(robertogallea\LaravelGreenPass\GreenPassServiceProvider::class);
Validation
To validate a green pass, use the greenpass
and greenpass_file
keyword in your validation rules array
public function rules()
{
return [
'greenpass_string' => 'greenpass',
//...
];
}
public function rules()
{
return [
'greenpass_uploaded_file' => 'greenpass_file',
//...
];
}
Utility GreenPassDecoder class
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);