PHP code example of bu4ak / roles

1. Go to this page and download the library: Download bu4ak/roles 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/ */

    

bu4ak / roles example snippets


// add 'HasRoles' trait to 'User' model
class User extends Authenticatable
{
    use Notifiable, HasRoles;
    ...

$user = User::first();
$user->assignRole(RoleType::ADMIN);

Route::get('/', function () {
    return view('welcome');
})->middleware(MiddlewareType::ADMIN);

$user->isAdmin();
$user->isManager();
$user->isUser();


User::admins()->get();
User::managers()->get();
User::users()->get();
bash
 php artisan migrate