mirhamit / acl
Access Level Control For Laravel
Requires
- php: ^7.2.5|>=8.0
- illuminate/auth: >=6.0
- illuminate/database: >=6.0
README
This package can be used to moderate roles and permissions of users in laravel application
Installation
open terminal and cd to your project root folder
install laravel :
laravel new laravel-acl-package
cd laravel-acl-package
setup your laravel auth Laravel Docs
we use laravel 8 Starter Pack and breeze in this section
composer require laravel/breeze --dev
php artisan breeze:install
npm install && npm run dev
Install this package with composer
composer require mirhamit/acl
You can publish and run the migrations with:
php artisan vendor:publish --provider="MirHamit\ACL\ACLServiceProvider" --tag="acl-migrations"
And publish language files for customize language
php artisan vendor:publish --provider="MirHamit\ACL\ACLServiceProvider" --tag="acl-lang"
Or publish both language and migrations
php artisan vendor:publish --provider="MirHamit\ACL\ACLServiceProvider"
And run the migration
php artisan migrate
Usage
Add HasPermission to your user model
use MirHamit\ACL\HasPermissions; class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable, HasPermissions; ... }
Give Permission To User:
$user->syncPermissions([1,2,3]); // Permission IDS
Give Role To User:
$user->syncRoles([1,2,3]); // Roles IDS
You can add multiple roles in roles
table and permissions in permissions
table and bind permission to role in permission_role
table
You can use middleware:
test-permission
is a permission bound to test-role
and bound to logged in user
Route::get('test', function () { return "salam"; })->middleware('role:test-role, test-permission');
Or you can use it for only permission bounded for user
Route::get('test', function () { return "salam"; })->middleware('permission: test-permission');
Or you can use it from Laravel Blade
@role('test-role') // or @role(['test-role', 'test-role2']) // user has role and can access to this section @endrole
And For Check Permission
@permission('test-permission') // or @permission(['test-permission', 'test-permission2']) // user has role and can access to this section @endpermission
Testing
As Soon As Possible
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review and check security vulnerabilities and report them in issues section.
Credits
License
The MIT License (MIT). Please see License File for more information.