Using ACL is a much common requirement for almost every project ranging from few users to big CRM's.
Laravel has multiple options for using ACL for your project or website.
Spatie has a nice & simple package for role based ACL which works with your existing user model. This package allows you to manage user permissions and roles in a database.
Once installed you can do stuff like this:
// Adding permissions to a user $user->givePermissionTo('edit articles'); // Adding permissions via a role $user->assignRole('writer');
Because all permissions will be registered on Laravel's gate, you can check if a user has a permission with Laravel's default can function:
Here are some examples how we can use it :
// You may also pass an array $user->givePermissionTo(['edit articles', 'delete articles']); $user->revokePermissionTo('edit articles'); $user->syncPermissions(['edit articles', 'delete articles']); $user->hasPermissionTo('edit articles'); $user->hasPermissionTo('1'); $user->hasPermissionTo(Permission::find(1)->id); $user->hasPermissionTo($somePermission->id); $user->hasAnyPermission(['edit articles', 'publish articles', 'unpublish articles']);
There are so many things you can do with with package. Head over & add it to your project.