Roles and Permissions are really common. The Filament ecosystem has a few options for how to do them. This example showcases the Shield plugin.
This example is based on the CMS Blog system.
All roles are created, and permissions are granted using the UI of the Filament Shield plugin.
The Post Resource must have additional publish_post
permission. To add such additional permissions, the Resource must implement the HasShieldPermissions
interface. Then, in the getPermissionPrefixes()
, provide all the policies.
app/Filament/Resources/PostResource.php:
use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions; class PostResource extends Resource implements HasShieldPermissions{ // ... public static function getPermissionPrefixes(): array { return [ 'view', 'view_any', 'create', 'update', 'delete', 'delete_any', 'publish', ]; }}