{"id":15631290,"url":"https://github.com/chiiya/filament-access-control","last_synced_at":"2025-05-15T10:06:53.893Z","repository":{"id":39744476,"uuid":"462873916","full_name":"chiiya/filament-access-control","owner":"chiiya","description":"Admin user, role and permission management for Laravel Filament","archived":false,"fork":false,"pushed_at":"2025-05-12T19:51:58.000Z","size":289,"stargazers_count":216,"open_issues_count":2,"forks_count":27,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-12T20:51:51.256Z","etag":null,"topics":["filament","laravel","permissions","php","roles"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chiiya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"chiiya"}},"created_at":"2022-02-23T19:16:28.000Z","updated_at":"2025-05-12T19:51:55.000Z","dependencies_parsed_at":"2023-02-16T21:15:56.312Z","dependency_job_id":"b027311f-85e1-4c2a-a556-6f3cd14b74a1","html_url":"https://github.com/chiiya/filament-access-control","commit_stats":{"total_commits":56,"total_committers":9,"mean_commits":6.222222222222222,"dds":0.4642857142857143,"last_synced_commit":"8d0b46d87d62e71b8d852aeebcf50e3fa930dc6e"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiiya%2Ffilament-access-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiiya%2Ffilament-access-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiiya%2Ffilament-access-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiiya%2Ffilament-access-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chiiya","download_url":"https://codeload.github.com/chiiya/filament-access-control/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253823352,"owners_count":21969844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filament","laravel","permissions","php","roles"],"created_at":"2024-10-03T10:39:49.871Z","updated_at":"2025-05-15T10:06:48.881Z","avatar_url":"https://github.com/chiiya.png","language":"PHP","funding_links":["https://github.com/sponsors/chiiya"],"categories":[],"sub_categories":[],"readme":"![filament-access-control](https://user-images.githubusercontent.com/15029301/155413160-9ba82064-3436-414f-a556-a0bff61528a0.png)\n\n# Filament Access Control\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/chiiya/filament-access-control.svg?style=flat-square)](https://packagist.org/packages/chiiya/filament-access-control)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/chiiya/filament-access-control/lint?label=code%20style)](https://github.com/chiiya/filament-access-control/actions?query=workflow%3Alint+branch%3Amaster)\n[![Total Downloads](https://img.shields.io/packagist/dt/chiiya/filament-access-control.svg?style=flat-square)](https://packagist.org/packages/chiiya/filament-access-control)\n\nOpinionated setup for managing admin users, roles and permissions within [Laravel Filament](https://github.com/laravel-filament/filament)\n\n## Features\n- Separate database table for filament admin users (separate model, separate guard, separate password broker)\n- Uses [spatie/laravel-permission](https://github.com/spatie/laravel-permission) for roles and permissions\n- Fully localized\n- CRUD resources for admin users, roles and permissions\n- Admin users _may_ belong to **one** role\n- Admin users can have direct permissions or indirect permissions through their role\n- When creating admin users through the admin interface, no password is specified. Instead, the user receives an email prompting them to set their password\n- Optional account expiry for admin users. Expired accounts are no longer able to log in\n- Optional email based two-factor authentication.\n\n## Installation\n\n1. Install the package via composer:\n\n```bash\ncomposer require chiiya/filament-access-control\n```\n\n2. Update your Filament Panel ServiceProvider and register the plugin:\n\n```php\nuse Chiiya\\FilamentAccessControl\\FilamentAccessControlPlugin;\n\nreturn $panel\n    -\u003edefault()\n    -\u003eid('admin')\n    -\u003epath('admin')\n    -\u003eplugin(FilamentAccessControlPlugin::make())\n```\n\nYou may remove any calls to `login()` or other methods that configure the authentication process, since the plugin\ntakes care of that.\n\n3. Publish the migrations and config, then run the migrations. Make sure you also publish\n   and run the [spatie/laravel-permission](https://github.com/spatie/laravel-permission) migrations\n   if you haven't done so yet.\n\n```bash\nphp artisan vendor:publish --tag=\"filament-access-control-migrations\"\nphp artisan vendor:publish --tag=\"filament-access-control-config\"\nphp artisan vendor:publish --provider=\"Spatie\\Permission\\PermissionServiceProvider\"\nphp artisan migrate\n```\n\n4. To seed the necessary base data (role \u0026 permissions), run `php artisan filament-access-control:install`\n   or call the `Chiiya\\FilamentAccessControl\\Database\\Seeders\\FilamentAccessControlSeeder` seeder in your database seeder.\n\n5. Create an admin user using `php artisan filament-access-control:user`. If you create users programmatically\n   (e.g. in your database seeder), make sure to assign them the `super-admin` role if you want them to be able to\n   access the role and user management.\n\nOptionally, you can publish the translations with:\n\n```bash\nphp artisan vendor:publish --tag=\"filament-access-control-translations\"\n```\n\nOptionally, you can publish the views with:\n\n```bash\nphp artisan vendor:publish --tag=\"filament-access-control-views\"\n```\n\n## Usage\n\n### Authorizing Resources, Pages \u0026 Actions\n\n#### Authorizing Resources\nTo authorize access to resources, use policies as described in the\n[Filament documentation](https://filamentphp.com/docs/2.x/admin/resources#authorization).\n\n```php\nclass ProductPolicy\n{\n    public function viewAny(FilamentUser $user): bool\n    {\n        return $user-\u003ecan('products.view');\n    }\n    \n    // ...\n}\n```\n\n#### Authorizing Pages\nThis package comes with a simple trait that you can use to authorize access to custom\npages based on a permission.\n\n```php\nuse Chiiya\\FilamentAccessControl\\Traits\\AuthorizesPageAccess;\n\nclass MyPage extends Page\n{\n    use AuthorizesPageAccess;\n    \n    public static string $permission = 'my-page.view';\n    \n    public function mount(): void\n    {\n        static::authorizePageAccess();\n    }\n}\n```\n\n#### Authorizing Actions\nOne way to authorize actions is to use the `visible()` method:\n\n```php\nButtonAction::make('exports')\n    -\u003evisible(fn () =\u003e Filament::auth()-\u003euser()-\u003ecan('exports.view'))\n```\n\n### Localizing Role \u0026 Permission Names\nRoles and permissions should have names that make them easy to use in code (e.g. `admin-users.update`).\nFor the admin you may however wish to localize them or make them more readable. You can do so by simply\nadding a JSON translation entry for the given role or permission name (e.g. `lang/en.json`):\n\n```json\n{\n    \"admin-users.update\": \"Admin Users → Edit\"\n}\n```\n\n### Feature: Account Expiry\nWith the optional account expiry feature, all accounts require an expiration date. When\naccounts are expired, they can no longer log in. To enable the account expiry feature,\nenable the feature flag in the config file:\n\n```php\n'features' =\u003e [\n    \\Chiiya\\FilamentAccessControl\\Enumerators\\Feature::ACCOUNT_EXPIRY,\n],\n```\n\nYou will also need to add the `EnsureAccountIsNotExpired` middleware to your filament auth middleware config in your\npanel service provider:\n\n```php\nuse Chiiya\\FilamentAccessControl\\Http\\Middleware\\EnsureAccountIsNotExpired;\n\n...\n-\u003eauthMiddleware([\n    Authenticate::class,\n    EnsureAccountIsNotExpired::class,\n]);\n```\n\n### Feature: Two-Factor Authentication\nWith the optional two-factor authentication feature, users must enter a verification code sent\nvia email upon login. To enable the two-factor authentication feature, enable the feature\nflag in the config file:\n\n```php\n'features' =\u003e [\n    \\Chiiya\\FilamentAccessControl\\Enumerators\\Feature::TWO_FACTOR,\n],\n```\n\n### Custom User Model\nTo use your own custom user model for the admin (instead of `Chiiya\\FilamentAccessControl\\Models\\FilamentUser`),\npoint the value of `user_model` in the `filament-access-control` config file to your own model.\n\n```php\n'user_model' =\u003e CustomFilamentUser::class,\n```\n\nPlease make sure that your model either extends the `FilamentUser` base case or implements the\n`Chiiya\\FilamentAccessControl\\Contracts\\AccessControlUser` interface.\n\n```php\nuse Chiiya\\FilamentAccessControl\\Models\\FilamentUser;\nuse Chiiya\\FilamentAccessControl\\Contracts\\AccessControlUser;\nuse Filament\\Models\\Contracts\\FilamentUser as FilamentUserInterface;\nuse Filament\\Models\\Contracts\\HasName;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass CustomFilamentUser extends FilamentUser\n{\n    // ...\n}\n\n// Or alternatively\nclass CustomFilamentUser extends Authenticatable implements AccessControlUser, FilamentUserInterface, HasName\n{\n    // ...\n}\n```\n\n### Extending Resources\nTo extend the resources used for managing admin users, roles and permissions, you can adjust the `resources` config \nvalue:\n\n```php\n    /*\n    |--------------------------------------------------------------------------\n    | Resources\n    |--------------------------------------------------------------------------\n    | Resources used for managing users, roles and permissions.\n    */\n    'resources' =\u003e [\n        'user' =\u003e FilamentUserResource::class,\n        'role' =\u003e RoleResource::class,\n        'permission' =\u003e PermissionResource::class,\n    ]\n```\n\nThe easiest way to extend the resources is to create your own resource classes that extend the default ones, and \noverwrite the following methods:\n\n```\n    public static function insertBeforeFormSchema(): array\n    {\n        return [];\n    }\n\n    public static function insertAfterFormSchema(): array\n    {\n        return [];\n    }\n\n    public static function insertBeforeTableSchema(): array\n    {\n        return [];\n    }\n\n    public static function insertAfterTableSchema(): array\n    {\n        return [];\n    }\n```\n\n## Screenshots\n![Screenshot of Admin Users - View](./art/admin_users_view.png)\n![Screenshot of Roles - Edit](./art/roles_edit.png)\n![Screenshot of Account Expired](./art/account_expired.png)\n![Screenshot of Two-Factor Authentication](./art/two_factor.png)\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchiiya%2Ffilament-access-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchiiya%2Ffilament-access-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchiiya%2Ffilament-access-control/lists"}