Dynamic ACL is a package that handles Access Control Level on your Laravel Application.
It's fast to running and simple to use.
Install and enjoy.
- Check permissions: Check routes dynamically on Admin permissions.
- Simple policy: Check user_id on your entities (if admin has access to this).
NOTE: you need to make your authentication (session based) system before.
NOTE: you should define name for your routes.
composer require iya30n/dynamic-aclphp artisan vendor:publishphp artisan migrateDon't worry about relationships, they handled already.
this command makes your first admin as super admin with fullAccess level.
php artisan make:admin --rolejust run your application and visit locahost:8000/admin/roles .
you'll see list of your roles.
you can create new one, edit or delete them.
after publish vendor you can change config on config/dynamicACL.php file.
- alignment: you can change UI alignment to rtl or ltr. also when you change your lang, roles CRUD will be changing in (fa, en).
- controllers_path: this is your controllers namespace.
- ignore_list: you can add your routes to be ignore on check permissions.
just add dynamicAcl middleware to your routes.
now you'll see list of the routes with dynamicAcl middleware on localhost:8000/admin/roles/create.
also this middleware will check your admin access to current route.
get list of the roles and use it on your own admin/user CRUD views.
you can use Role model to write your own queries and get list of the roles.
use Iya30n\DynamicAcl\Models\Role;you can use sync, attach, dettach method to assign roles to a user.
$user->roles()->sync([1, 2, 3,...]);$user->roles()->get();call hasPermission method on user and pass the route name.
auth()->user()->hasPermission('admin.articles.create');check if user has access to any routes of an entity:
auth()->user()->hasPermission('admin.articles.*')also you can check if user has access to his own entity:
$user->hasPermission('admin.articles.update', $article);with custom relation_key (default is 'user_id'):
$user->hasPermission('admin.articles.update', $article, 'owner_id');NOTE: you should use route model binding on your controllers.
it's very simple too.
just add authorize middleware to your routes. it gets a parameter as a foreign key (default is user_id).
this middleware will check the foreign key on your entity.