Laravel ACL adds role based permissions to built in Auth System of Laravel 9.0+. ACL middleware protects routes and even crud controller methods.
Install the package using composer
composer require kodeine/laravel-acl
If you need to support Laravel 5.x, make sure to install version 1.x
composer require kodeine/laravel-acl "^1.0"
'providers' => [
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
'Illuminate\Auth\AuthServiceProvider',
...
'Kodeine\Acl\AclServiceProvider',
],
$ php artisan vendor:publish --provider="Kodeine\Acl\AclServiceProvider"
Once you publish, it publishes the configuration file where you can:
- Use your own models: Define your own models which should extend to Acl models.
- Use your own guard: Define a guard other than laravel default for user recovery.
app/Http/Kernel.php
.protected $routeMiddleware = [
....
'acl' => 'Kodeine\Acl\Middleware\HasPermission',
];
User
model.use Kodeine\Acl\Traits\HasRole;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, HasRole;
}
Please note that if you are upgrading to 6.0 from a previous version, the default column type for the id on the users table has changed. On certain databases foreign keys can only be defined with matching column types. As such, you will need to change the id column on your users table to bigInteger in to user this package.
php artisan migrate
Follow along the Wiki to find out more.
Here's the TODO list for the next release.
June 14 2022
September 14 2019
September 13, 2019
*September 22, 2016**
*September 20, 2016**
September 19, 2016
June 14, 2015
March 28, 2015
User::role('admin')->get();
will list all users having admin
role.March 7, 2015
is()
and can()
methods now support comma for AND
and pipe as OR
operator. Or pass an operator as a second param. more informationSupport follows PSR-2 PHP coding standards, and semantic versioning.
Please report any issue you find in the issues page. Pull requests are welcome.