LaravelPackages.net
Acme Inc.
Toggle sidebar
sunxyw/laravel-quick-role

A package to quickly build a simple roles manager system

8
0
v1.0.5
About sunxyw/laravel-quick-role

sunxyw/laravel-quick-role is a Laravel package for a package to quickly build a simple roles manager system. It currently has 0 GitHub stars and 8 downloads on Packagist (latest version v1.0.5). Install it with composer require sunxyw/laravel-quick-role. Discover more Laravel packages by sunxyw or browse all Laravel packages to compare alternatives.

Last updated

Laravel Quick Role

A package to quickly build a simple roles manager system.

Installing

$ composer require sunxyw/laravel-quick-role

Usage

First, add the Sunxyw\LaravelQuickRole\HasRole trait to your User model:

use Sunxyw\LaravelQuickRole\HasRole;

class User extends Authenticatable
{
    use HasRole;
}

Then, create a new role for testing:

use Sunxyw\LaravelQuickRole\Models\Role;

Role::create([
    'name' => 'admin',
    'title' => 'Administrator',
    'color' => 'FF5555',
]);

Now, you can assign a role to a user by:

$user = User::find(1);
$user->assignRole('admin'); // By name
$user->assignRole(Role::find(1)); // By instance
$user->assignRole(1); // By ID

You can check user's role by:

$user->hasRole('admin'); // Accept name, ID and instance
// or
$user->hasAnyRole(['admin', 'leader']);

License

MIT

Star History Chart