PHP code example of apirelio / laravel

1. Go to this page and download the library: Download apirelio/laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

apirelio / laravel example snippets


Route::middleware(['auth:sanctum', 'apirelio'])->group(function (): void {
    Route::post('/invoices/{invoice}/send', SendInvoiceController::class);
});

use Apirelio\Laravel\Middleware\TrackApiRequest;

Route::middleware(TrackApiRequest::class)->group(/* ... */);

use Illuminate\Http\Request;
use Apirelio\Laravel\Data\ApirelioApplication;
use Apirelio\Laravel\Data\ApirelioCustomer;
use Apirelio\Laravel\Facades\Apirelio;

Apirelio::resolveCustomerUsing(
    static function (Request $request): ?ApirelioCustomer {
        $client = $request->user();

        return $client === null
            ? null
            : new ApirelioCustomer(
                id: (string) $client->company_id,
                name: $client->company->name,
                plan: $client->company->plan,
            );
    },
);

Apirelio::resolveApplicationUsing(
    static fn (Request $request): ?ApirelioApplication =>
        $request->user()?->api_client_id === null
            ? null
            : new ApirelioApplication(
                id: (string) $request->user()->api_client_id,
                name: 'ERP connector',
            ),
);

Apirelio::setErrorCode('INVALID_CURRENCY');

'metadata_keys' => ['integration_type', 'region'],

Apirelio::addMetadata([
    'integration_type' => 'accounting',
    'region' => 'eu-central',
]);
bash
php artisan queue:work
php artisan schedule:work