RBAC - v1.0.0
Usage
The package exposes its functionality through five layers — models, traits, middleware, Blade directives, and Gate integration — plus a set of Artisan commands for CRUD. Each has its own page below.
Topics
- Roles — the
Rolemodel, hierarchy, slug helpers - Permissions — the
Permissionmodel, slug helpers - User traits (
HasRoles,HasPermissions) - Middleware (
permission:slug,slug) - Blade directives (
@role,@permission) - Gate integration
- Artisan commands
Quick reference
// Models
$editor = Role::create(['name' => 'editor']);
$publish = Permission::create(['name' => 'posts.publish']);
$editor->permissions()->attach($publish);
// Traits (on User)
$user->assignRole('editor');
$user->hasRole('editor');
$user->hasPermissionTo('posts.publish');
// Gate
$user->can('posts.publish');
Gate::allows('posts.publish');
// Middleware
Route::middleware('permission:posts.publish');
// Blade
@role('editor') ... @endrole
@permission('posts.publish') ... @endpermission
# Artisan
php artisan role:create editor
php artisan user:assign-role user@example.com editor