RBAC - v1.0.0
Getting Started
A five-minute path from install to a working role / permission check.
1. Install
composer require artisanpack-ui/rbac
php artisan migrate
2. Add the traits to your User model
use ArtisanPackUI\Rbac\Concerns\HasPermissions;
use ArtisanPackUI\Rbac\Concerns\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasPermissions;
use HasRoles;
}
3. Create a role and a permission
use ArtisanPackUI\Rbac\Models\Permission;
use ArtisanPackUI\Rbac\Models\Role;
$editor = Role::create(['name' => 'editor']);
$publish = Permission::create(['name' => 'posts.publish']);
$editor->permissions()->attach($publish);
Or use Artisan:
php artisan role:create editor
php artisan permission:create posts.publish
4. Assign the role to a user
$user->assignRole('editor');
Or:
php artisan user:assign-role user@example.com editor
5. Check authorization
$user->hasRole('editor'); // true
$user->hasPermissionTo('posts.publish'); // true
$user->can('posts.publish'); // true — via Gate integration
In a route:
Route::get('/posts/{post}/publish', PublishController::class)
->middleware('permission:posts.publish');
In a Blade view:
@permission('posts.publish')
<button>Publish</button>
@endpermission
@role('editor')
<a href="/editor">Editor dashboard</a>
@endrole
Next steps
- Usage — full reference for the traits, middleware, directives, and Gate integration.
- Advanced — extending the base models, listening for events, tuning the cache.
- Installation — requirements, configuration, and integration with existing schemas.