siriondev/consellrep

Composer package per a la integració amb el procés de validació de la Identitat Digital Republicana del Consell per la República Catalana

v1.1.0 2021-05-23 01:56 UTC

This package is auto-updated.

Last update: 2025-06-23 10:44:14 UTC


README

Installation

This package can be used with Laravel 8.0 or higher.

Install the package via composer:

composer require siriondev/consellrep

The service provider will automatically get registered. You may manually add the service provider in your config/app.php file:

'providers' => [
    // ...
    Siriondev\ConsellRepublica\Providers\ConsellRepublicaProvider::class,
];

Config and Translations

You should publish the translations and the config/cxr.php config file with:

php artisan vendor:publish --tag="consellrep-config"
php artisan vendor:publish --tag="consellrep-translations"

Migrations

You may also want to publish the migration to add the idrepublicana field into your users table:

php artisan vendor:publish --tag="consellrep-migrations"

Clear your config cache

php artisan optimize

Usage

Validator

You can use the idrepublicana rule to check whether the user input is valid or not.

public function rules()
{
    return [
        'id' => 'required|idrepublicana'
    ];
}

You can also set parameters to check whether the IDR is valid, active, underaged, or just check the format.

public function rules()
{
    return [
        'id' => 'required|idrepublicana:active,valid,underaged,format'
    ];
}

Facade

You can also use the IdentitatDigitalRepublicana Facade. The validate method returns an object that can be used to check different attributes from the IDR.

use Siriondev\ConsellRepublica\Facades\IdentitatDigitalRepublicana;

class Controller extends BaseController
{
    public function register(Request $request)
    {
        $idr = IdentitatDigitalRepublicana::validate($request->id);

        if ($idr->getStatus()) {    // Request OK

            $idr->isValid();        // IDR is valid

            $idr->isActive();       // IDR is active

            $idr->isUnderaged();    // IDR is underaged

            $idr->isFormat();       // IDR format correct (C-999-99999)

        } else {

            $idr->getMessage();     // Get the error message
        }
    }
}