Integrating Filament Shield with Filament Spatie Laravel Backup
Integrating Filament Shield with Filament Spatie Laravel Backup
If you've installed Filament Shield and Filament Spatie Laravel Backup but are struggling to make them work together, this guide will help you link them properly by setting up Spatie permissions.
Step 1: Define Permissions
Spatie Permission allows role-based access control. Run the following command to generate permissions:
php artisan shield:generate
This will create a set of permissions for your Filament resources, but you need to manually define the permissions for backups.
Step 2: Add Backup Permissions
Run the following commands to create permissions for backup actions:
php artisan permission:create-permission download-backup
php artisan permission:create-permission delete-backup
Alternatively, you can define these permissions in a Seeder and run:
php artisan db:seed --class=PermissionSeeder
Example PermissionSeeder
class:
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
class PermissionSeeder extends Seeder
{
public function run()
{
Permission::firstOrCreate(['name' => 'download-backup']);
Permission::firstOrCreate(['name' => 'delete-backup']);
}
}
Step 3: Assign Permissions to Roles
Navigate to Filament Admin Panel → Shield → Roles, and assign the download-backup
and delete-backup
permissions to the appropriate roles.
Step 4: Verify Backup Page Actions
Now, when you navigate to the Filament Backup section, the download and delete options should be visible based on user permissions.
Conclusion
By linking Shield and Filament Spatie Laravel Backup with Spatie permissions, you gain precise control over who can access backup features within your Filament admin panel. This ensures security while maintaining ease of use for administrators.