Skip to content
Nav

Creating keys

composer require langsys/laravel-api-keys
Packagist version Monthly downloads License PHP 8.2+ Laravel 10 / 11 / 12
use Langsys\ApiKeys\Models\ApiKey;
$key = ApiKey::create(['name' => 'mobile-app', 'type' => 'write']);
// The plaintext is available exactly once, right after generation:
$key->plain_key; // "x7Qa...64 chars" — show this to the user now; it is never stored.

Only a sha256 hash of the key is persisted (key_hash). Resolve a key from a plaintext value with ApiKey::getByKey($plain) (returns null if unknown).

Key types: read, write, and ip_write.

Feedback