Documentation/PHP / Laravel

PHP / Laravel

Instrument Laravel APIs.

Add customer-aware request analytics with package discovery, route middleware and queue-backed delivery.

Laravel 11–12Package v0.2.0Production ready
01

Quickstart

Install and add your key.

Laravel package discovery registers Apirelio automatically. Publish the configuration and copy the ingestion key displayed once in your project settings.

Terminalbash
composer require apirelio/laravel:^0.2
php artisan vendor:publish --tag=apirelio-config
.envini
APIRELIO_ENABLED=true
APIRELIO_ENDPOINT=https://api.apirelio.com
APIRELIO_API_KEY=apr_live_xxxxxxxxx
APIRELIO_SERVICE=billing-api
APIRELIO_ENVIRONMENT=production
APIRELIO_RELEASE=2026.07.30.1
APIRELIO_TRANSPORT=queue
Production default

The queue transport keeps Apirelio network activity outside the observed customer request.

02

Request tracking

Attach the middleware.

Apply apirelio after authentication to the API route groups that matter. Laravel route templates are retained, so concrete identifiers and query strings never become endpoint dimensions.

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

Customer context

Identify the B2B account.

Register a resolver in an application service provider. Use a stable external ID; names and plans can evolve without breaking customer history.

AppServiceProvider.phpphp
use Illuminate\Http\Request;
use Apirelio\Laravel\Data\ApirelioCustomer;
use Apirelio\Laravel\Facades\Apirelio;

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

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

Diagnostics

Add actionable context.

HTTP status is automatic. Set a stable error code when the response body does not expose one, and only add low-cardinality metadata allowed in config/apirelio.php.

Controller or servicephp
Apirelio::setErrorCode('INVALID_CURRENCY');

Apirelio::addMetadata([
    'integration_type' => 'accounting',
    'region' => 'eu-central',
]);
Allow-list required

Unlisted keys, complex values and known secret-like fields are discarded before delivery.

05

Reliability

Run the worker and scheduler.

The queue transport batches events through a locked local buffer. Keep both normal Laravel processes running so full and low-traffic batches are delivered.

Production processesbash
php artisan queue:work
php artisan schedule:work
Q

queue

Recommended production transport with off-request delivery.

S

sync

Immediate delivery for local diagnostics and setup verification.

F

file-buffer

Locked NDJSON buffering with size and interval flushes.