devtical/filament-sanctum
Manage Laravel Sanctum API tokens directly from your Filament panel. Create, list, and revoke personal access tokens, define custom abilities and expiration presets, restrict access with gates, and display the page in the sidebar or user menu.
Manage Laravel Sanctum personal access tokens from your Filament panel.
Install the package and Sanctum:
composer require devtical/filament-sanctum laravel/sanctum
Publish Sanctum and run migrations:
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate
Add the HasApiTokens trait to your user model:
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens;
}
Register the plugin in your Filament panel provider:
use Devtical\Sanctum\SanctumPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(SanctumPlugin::make());
}
Publish the package config (optional):
php artisan vendor:publish --tag=filament-sanctum-config
Publish translations (optional):
php artisan vendor:publish --tag=filament-sanctum-translations
By default, the Sanctum page appears in the user menu. To show it in the sidebar instead:
// config/filament-sanctum.php
'navigation' => [
'slug' => 'sanctum',
'sidebar_menu' => [
'enabled' => true,
],
'user_menu' => [
'enabled' => false,
],
],
Customize the abilities available when creating a token:
'abilities' => [
'columns' => 4,
'allow_expiration' => true,
'default_expiration_days' => 30,
'expiration_presets' => [7, 30, 60, 90],
'list' => [
'posts:read' => 'Read posts',
'posts:write' => 'Write posts',
],
],
Restrict access to the Sanctum page using a Laravel gate:
'authorization' => [
'enabled' => true,
'gate' => 'manage-api-tokens',
],
Define the gate in a service provider:
Gate::define('manage-api-tokens', fn (User $user) => $user->isAdmin());
composer test
Format code:
composer format
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?