Admin user, role and permission management for Laravel Filament

Overview

filament-access-control

Filament Access Control

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Opinionated setup for managing admin users, roles and permissions within Laravel Filament

Features

  • Separate database table for filament admin users (separate model, separate guard, separate password broker)
  • Uses spatie/laravel-permission for roles and permissions
  • Adds the missing password reset flow to Filament
  • Fully localized
  • CRUD resources for admin users, roles and permissions
  • Admin users may belong to one role
  • Admin users can have direct permissions or indirect permissions through their role
  • When creating admin users through the admin interface, no password is specified. Instead, the user receives an email prompting them to set their password
  • Optional account expiry for admin users. Expired accounts are no longer able to log in
  • Optional email based two-factor authentication.

Installation

  1. Install the package via composer:
composer require chiiya/filament-access-control
  1. Update your config/filament.php file to use the package's guard and Login page:
'auth' => [
    'guard' => env('FILAMENT_AUTH_GUARD', 'filament'),
    'pages' => [
        'login' => \Chiiya\FilamentAccessControl\Http\Livewire\Login::class,
    ],
],
  1. Publish the migrations and config, then run the migrations. Make sure you also publish and run the spatie/laravel-permission migrations if you haven't done so yet.
php artisan vendor:publish --tag="filament-access-control-migrations"
php artisan vendor:publish --tag="filament-access-control-config"
php artisan migrate
  1. To seed the necessary base data (role & permissions), run php artisan filament-access-control:install or call the Chiiya\FilamentAccessControl\Database\Seeders\FilamentAccessControlSeeder seeder in your database seeder.

  2. Create an admin user using php artisan filament-access-control:user. If you create users programmatically (e.g. in your database seeder), make sure to assign them the super-admin role if you want them to be able to access the role and user management.

Optionally, you can publish the translations with:

php artisan vendor:publish --tag="filament-access-control-translations"

Optionally, you can publish the views with:

php artisan vendor:publish --tag="filament-access-control-views"

Usage

Authorizing Resources, Pages & Actions

Authorizing Resources

To authorize access to resources, use policies as described in the Filament documentation.

class ProductPolicy
{
    public function viewAny(FilamentUser $user): bool
    {
        return $user->can('products.view');
    }
    
    // ...
}

Authorizing Pages

This package comes with a simple trait that you can use to authorize access to custom pages based on a permission.

use Chiiya\FilamentAccessControl\Traits\AuthorizesPageAccess;

class MyPage extends Page
{
    use AuthorizesPageAccess;
    
    public static string $permission = 'my-page.view';
    
    public function mount(): void
    {
        static::authorizePageAccess();
    }
}

Authorizing Actions

One way to authorize actions is to use the visible() method:

ButtonAction::make('exports')
    ->visible(fn () => Filament::auth()->user()->can('exports.view'))

Localizing Role & Permission Names

Roles and permissions should have names that make them easy to use in code (e.g. admin-users.update). For the admin you may however wish to localize them or make them more readable. You can do so by simply adding a JSON translation entry for the given role or permission name (e.g. lang/en.json):

{
    "admin-users.update": "Admin Users → Edit"
}

Feature: Account Expiry

With the optional account expiry feature, all accounts require an expiration date. When accounts are expired, they can no longer log in. To enable the account expiry feature, enable the feature flag in the config file:

'features' => [
    \Chiiya\FilamentAccessControl\Enumerators\Feature::ACCOUNT_EXPIRY,
],

You will also need to add the EnsureAccountIsNotExpired middleware to your filament auth middleware config:

use Chiiya\FilamentAccessControl\Http\Middleware\EnsureAccountIsNotExpired;

'middleware' => [
    'auth' => [
        Authenticate::class,
        EnsureAccountIsNotExpired::class,
    ],
]

Feature: Two-Factor Authentication

With the optional two-factor authentication feature, users must enter a verification code sent via email upon login. To enable the two-factor authentication feature, enable the feature flag in the config file:

'features' => [
    \Chiiya\FilamentAccessControl\Enumerators\Feature::TWO_FACTOR,
],

Screenshots

Screenshot of Admin Users - View Screenshot of Roles - Edit Screenshot of Reset Password Screenshot of Account Expired Screenshot of Two-Factor Authentication

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

Comments
Releases(1.5.0)
  • 1.5.0(Aug 2, 2022)

  • 1.4.0(Jul 6, 2022)

    What's Changed

    • Bump dependabot/fetch-metadata from 1.3.1 to 1.3.3 by @dependabot in https://github.com/chiiya/filament-access-control/pull/9
    • Add support for Laravel 8 and PHP 8.0 by @stephenjude in https://github.com/chiiya/filament-access-control/pull/7
    • Fixed validation for role resource by @stephenjude in https://github.com/chiiya/filament-access-control/pull/7

    New Contributors

    • @stephenjude made their first contribution in https://github.com/chiiya/filament-access-control/pull/7

    Full Changelog: https://github.com/chiiya/filament-access-control/compare/1.3.5...1.4.0

    Source code(tar.gz)
    Source code(zip)
  • 1.3.5(Jul 1, 2022)

    What's Changed

    • Fixed config serialization
    • Added config option password_hint for setting a helper text for the password field on the reset-password page

    Full Changelog: https://github.com/chiiya/filament-access-control/compare/1.3.0...1.3.5

    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Mar 7, 2022)

    What's Changed

    • Added trait for authorizing page access
    • Improved documentation

    Full Changelog: https://github.com/chiiya/filament-access-control/compare/1.2.0...1.3.0

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Feb 25, 2022)

    What's Changed

    • Added missing translations
    • Added new optional two-factor-authentication feature (see README on how to enable)
    • Updated and rename filament:create-user command to filament-access-control:user
    • Added filament-access-control:install command to create base role and permissions

    Full Changelog: https://github.com/chiiya/filament-access-control/compare/1.1.0...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Feb 23, 2022)

    What's Changed

    • The account expiry date is now optional (only affects installations where the ACCOUNT_EXPIRY feature is enabled)

    Full Changelog: https://github.com/chiiya/filament-access-control/compare/1.0.1...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Feb 23, 2022)

Owner
Elisha Witte
Fullstack developer, Laravel & API enthusiast.
Elisha Witte
Filament-spatie-laravel-activitylog - View your activity logs inside of Filament. ⚡️

View your activity logs inside of Filament. This package provides a Filament resource that shows you all of the activity logs created using the spatie

Ryan Chandler 35 Sep 21, 2022
A convenient helper for using the laravel-seo package with Filament Admin and Forms

Combine the power of Laravel SEO and Filament PHP. This package is a convenient helper for using the laravel-seo package with Filament Admin and Forms

Ralph J. Smit 26 Jul 24, 2022
Easily add Laravel Telescope and Horizon to Filament admin panel.

Filament Debugger This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Installation You can inst

Stephen Jude 2 Sep 5, 2022
Access laravel log through Filament admin panel

Access laravel log through Filament admin panel Features Syntax highlighting Quickly jump between start and end of the file Refresh log contents Clear

Guilherme Saade 13 Sep 17, 2022
A media picker plugin for Filament Admin.

Filament Curator A media picker plugin for Filament Admin. ‼️ This package is still in development ‼️ This package does not work with Spatie Media Lib

Adam Weston 53 Sep 21, 2022
Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items.

Filament Quick Create Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items from any page. Installation Instal

Adam Weston 25 Sep 27, 2022
Filament Admin Panel application installer.

Filament Installer Install globally with composer. composer global require awcodes/filament-installer Now you can run the new command to quickly set u

Adam Weston 5 Sep 21, 2022
A demo of how to use filament/forms to build a user-facing Form Builder which stores fields in JSON.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Dan Harrin 37 Sep 13, 2022
Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5.

ENTRUST (Laravel 5 Package) Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5. If you are looking for the Laravel 4 ve

Zizaco 6.1k Sep 16, 2022
Implementation Package Spatie/Laravel-Permission

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

M Rizal 3 Sep 12, 2021
A simple profile management page for Filament. ✨

A simple profile page for Filament. This package provides a very simple Profile page that allows the current user to manage their name, email address

Ryan Chandler 53 Sep 21, 2022
Customize Login and Register Page for User/Admin in Laravel v8

Customize Login and Register Page for User/Admin in Laravel v8

Gaurang Kumar 1 Jan 28, 2022
A CMS start kit for websites, built on Filament and Laravel.

TrovCMS TrovCMS is a start kit for websites, built on Filament and Laravel. Install globally with composer. composer global require trovcms/installer

TrovCMS 11 Sep 21, 2022
User authentication REST API with Laravel (Register, Email verification, Login, Logout, Logged user data, Change password, Reset password)

User Authentication API with Laravel This project is a user authentication REST API application that I developed by using Laravel and MySql. Setup Fir

Yusuf Ziya YILDIRIM 3 Aug 23, 2022
Social login for Filament through Laravel Socialite

Social login for Filament through Laravel Socialite Add OAuth login through Laravel Socialite to Filament. Installation You can install the package vi

Dutch Coding Company 36 Sep 14, 2022
This package provides a Filament resource to view all Laravel sent emails.

This package provides a Filament resource to view all Laravel outgoing emails. It also provides a Model for the database stored emails. Installation Y

Ramón E. Zayas 13 Sep 21, 2022
Easily interact and control your feature flags from Filament

Easily interact and control your feature flags from Filament

Ryan Chandler 23 Aug 11, 2022
Add a general-purpose tools page to your Filament project. 🛠

Add a general-purpose tools page to your Filament project. Installation You can install the package via Composer: composer require ryangjchandler/fila

Ryan Chandler 18 May 15, 2022
The Most Popular JavaScript Calendar as a Filament Widget 💛

The Most Popular JavaScript Calendar as a Filament Widget ?? Features Accepts all configurations from FullCalendar Event click and drop events Upcomin

Guilherme Saade 40 Sep 25, 2022