PHP code example of sunxyw / laravel-quick-role

1. Go to this page and download the library: Download sunxyw/laravel-quick-role library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sunxyw / laravel-quick-role example snippets


use Sunxyw\LaravelQuickRole\HasRole;

class User extends Authenticatable
{
    use HasRole;
}

use Sunxyw\LaravelQuickRole\Models\Role;

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

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

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