This package can be used to moderate roles and permissions of users in laravel application
open terminal and cd to your project root folder
install laravel :
laravel new laravel-acl-package
cd laravel-acl-packagesetup 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 devInstall this package with composer
composer require mirhamit/aclYou 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 migrateAdd 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
@endroleAnd For Check Permission
@permission('test-permission')
// or @permission(['test-permission', 'test-permission2'])
// user has role and can access to this section
@endpermissionAs Soon As PossiblePlease see CHANGELOG for more information on what has changed recently.
Please review and check security vulnerabilities and report them in issues section.
The MIT License (MIT). Please see License File for more information.