PHP code example of oltrematica / laravel-role-lite

1. Go to this page and download the library: Download oltrematica/laravel-role-lite 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/ */

    

oltrematica / laravel-role-lite example snippets


'table_names' => [
    // Table for storing roles
    'roles' => 'roles',
    
    // Your users table (usually 'users')
    'users' => 'users',
    
    // Pivot table for role-user relationship
    'role_user' => 'role_user',
],

'model_names' => [
    // If you want to use a custom user model, specify it here
    // Otherwise, it will use the model defined in auth.providers.users.model
    'user' => null,
],


enum Roles: string
{
    case ADMIN = 'admin';
    case EDITOR = 'editor';
    case MODERATOR = 'moderator';
}


// Assign a role to a user
$user->assignRole('admin');

// or you can use Enum 
$user->assignRole(\App\Enums\Roles::ADMIN);

$user->assignRoles(['editor', 'moderator']);

if ($user->hasRole('admin')) {
    // User has admin role
}

// or

if ($user->hasRole(\App\Enums\Roles::ADMIN)) {
    // User has admin role
}

if ($user->hasAnyRole(['admin', 'editor'])) {
    // User has either admin or editor role
}

// or

if ($user->hasAnyRole([Roles::ADMIN, Roles::EDITOR])) {
    // User has either admin or editor role
}


if ($user->hasAllRoles(['admin', 'editor'])) {
    // User has both admin and editor roles
}

// or

if ($user->hasAllRoles([Roles::ADMIN, Roles::EDITOR])) {
    // User has both admin and editor roles
}

if ($user->hasNoRoles()) {
    // User has no roles
}

if ($user->hasSomeRoles()) {
    // User has at least one role
}
bash
php artisan vendor:publish --tag=oltrematica-role-lite-migrations
bash
php artisan migrate
bash
php artisan vendor:publish --tag=oltrematica-role-lite-config
shell
composer analyse