phpsa/filament-authentication
Installation Run:
composer require phpsa/filament-authentication
php artisan filament-authentication:install
This publishes migrations, config, and sets up Spatie Permissions if not already configured.
Run Migrations
php artisan migrate
Ensures the users, roles, and permissions tables are created.
Register the Resource
Add the FilamentAuthentication\Resources\UserResource to your app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->resources([
// ... other resources
\FilamentAuthentication\Resources\UserResource::class,
]);
}
Access the Admin Panel
Visit /admin and navigate to the Users section to manage users, roles, and permissions.
Create a User
name, email, password).super-admin role (created by default during installation).Verify Permissions
access admin panels).name, email) and filters (e.g., role).UserResource to add custom fields (e.g., department):
// app/Filament/Resources/UserResource.php
public static function form(Form $form): Form
{
return $form
->schema([
// ... default fields
TextInput::make('department')->required(),
]);
}
hasRole() or givePermissionTo() in policies:
// app/Policies/UserPolicy.php
public function viewAny(User $user)
{
return $user->hasRole('admin');
}
Management, Content) in config/permission.php.AdminPanelProvider:
->resources([
UserResource::class, // Only accessible to admins
])
->policy(UserResource::class, UserPolicy::class),
FilamentAuthentication\Auth\Login class or using Filament’s built-in auth callbacks.If using spatie/laravel-tenancy, extend the UserResource to include tenant-specific fields:
public static function table(Table $table): Table
{
return $table
->columns([
// ... default columns
TextColumn::make('current_tenant_id')->numeric(),
]);
}
Trigger notifications on user creation/role assignment:
// app/Filament/Resources/UserResource.php
protected static function afterCreate(array $data): void
{
Notification::send($data['user'], new UserCreatedNotification());
}
Expose user management via API by creating a Filament API resource:
php artisan make:filament-resource UserApiResource --api
Reuse the same logic as UserResource but restrict fields/methods.
Missing Spatie Permissions Setup
spatie/laravel-permission isn’t installed, the package will fail silently. Ensure you run:
composer require spatie/laravel-permission
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate
Role/Permission Caching
php artisan cache:clear
php artisan config:clear
Filament Resource Conflicts
User resources. Use a unique namespace (e.g., App\Filament\Resources\AdminUserResource).Password Hashing
User model’s setPasswordAttribute.Permission Denied Errors
filament-authentication.log (if enabled in config) or enable debug mode:
// config/filament.php
'debug' => env('FILAMENT_DEBUG', true),
SELECT * FROM model_has_roles WHERE model_type = 'App\Models\User';
Migration Issues
php artisan migrate:rollback
php artisan migrate --force
Resource Not Showing
AdminPanelProvider and the user has the access admin panels permission.Custom Role Names
Modify default roles (e.g., super-admin) in the UserResource:
// app/Filament/Resources/UserResource.php
public static function getRelations(): array
{
return [
Relationships\BelongsToMany::make('roles')
->relationshipName('roles')
->title('Roles')
->items([
'admin', 'editor', 'viewer', // Customize as needed
]),
];
}
Bulk Role Assignment Use the table’s bulk edit feature to assign roles to multiple users without opening each record.
Audit Logging Enable Filament’s audit logs for user/role changes:
// config/filament.php
'audit_logging' => true,
Localization Publish translations for multi-language support:
php artisan vendor:publish --tag=filament-authentication-translations
Testing Use Filament’s testing helpers to assert UI interactions:
$this->actingAs($user)
->get('/admin/users')
->assertSee('Users');
How can I help you explore Laravel packages today?