PHP code example of juhniorsantos / laravel-simple-acl

1. Go to this page and download the library: Download juhniorsantos/laravel-simple-acl 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/ */

    

juhniorsantos / laravel-simple-acl example snippets


$addUsers = Permission::create([
    'label' => 'add-users',
    'description' => 'User is allowed to create new users',
    'sort_index' => 1,
]);

$removeUsers = Permission::create([
    'label' => 'remove-users',
    'description' => 'User is allowed to remove users',
    'sort_index' => 2,
]);

Role::create([
    'label' => 'admin',
    'sort_index' => 1,
])->attachPermission($addUsers)->attachPermission($removeUsers);

Role::create([
    'label' => 'leader',
    'sort_index' => 2,
])->attachPermission($addUsers);

$user->attachRole(Role::hasLabel('admin')->first());
$user->detachRole(Role::hasLabel('leader')->first());

if ($user->can('add-users')) {
    // do something
}