Installation
Requirements
- PHP
^8.2 - Laravel
^11.0 | ^12.0 laravel/sanctum— a resolved key authenticates through the Sanctum guard
The package works in any Laravel application. Installed on top of the Laravel API Boilerplate it auto-wires into the existing admin stack and audit log.
Install
composer require mrsuner/laravel-api-keys
php artisan vendor:publish --tag=api-keys-config # optional
php artisan migrate
The service provider is auto-discovered. It binds the ApiKeyService singleton,
registers the migrations, mounts the user and admin routes, and registers the
api.key and api.ability middleware aliases — so you do not need to edit
bootstrap/app.php.
What gets installed
Two migrations are published into your schema:
api_keys— one row per key: its owner (user_id),name, the plaintextkey_prefixfor display, thekey_hash(SHA-256 of the token),environment,abilities, an optional per-keyrate_limit,expires_at, theis_activeflag,revoked_at, usage counters (last_used_at,last_used_ip,request_count), timestamps and soft deletes.api_key_usage_logs— one row per request (when usage logging is enabled):method, normalizedendpoint,ip,status_codeandresponse_time_ms.
The
user_idcolumn is aforeignUlidso it matches the boilerplate’s ULID-keyeduserstable. On a standard integer-keyed app, pointapi-keys.user_modelat yourUsermodel and adjust the column type to suit.
Verify
php artisan migrate:status
You should see the two API-key migrations applied. Resolve the service anywhere to confirm the binding:
$keys = app(\Mrsuner\ApiKeys\Services\ApiKeyService::class);
Continue with Configuration.