PHP code example of obrainwave / access-tree

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

    

obrainwave / access-tree example snippets


$data = [
     'name' => 'Add User',
     'status' => 1 or 0
   ];
$create = createAccess($data, 'permission');
echo $create;

$data = [
     'data_id' => id from created permissions table when installed package // 3,
     'name' => 'Add User',
     'status' => 1 or 0
   ];
$update = updateAccess($data, 'permission');
echo $update;

$data = [
     'name' => 'Admin',
     'status' => 1 or 0
   ];
$permission_ids = array of ids from created permissions table when installed package // array(1, 5, 4);
$create = createAccess($data, 'role', $permission_ids);
echo $create;

$data = [
     'data_id' => role id // 5,
     'name' => 'Admin Staff',
     'status' => 1 or 0
   ];
$permission_ids = array of ids from created permissions table when installed package // array(10, 6, 3);
$update = updateAccess($data, 'role', $permission_ids);
echo $update;
 
$roles = array of ids from created roles table when installed package // array(2, 5);
$user_id = id of a user from App\Models\User // 1;
$user_role = createUserRole($roles, $user_id);
echo $user_role;

$roles = array of ids from created roles table when installed package // array(2, 5);
$user_id = id of a user from App\Models\User // 5;
$user_role = updateUserRole($roles, $user_id);
echo $user_role;

checkPermission(string slug_of_permission) // returns true or false
or
checkPermissions(array slug_of_permissions) // returns true or false

@if(checkPermission('add_user')
// Do some stuff
@else
throw new \Exception("Access Forbidden", 1);
@endif

@if(checkPermissions(['add_user', 'view_user'])
// Do some stuff
@else
throw new \Exception("Access Forbidden", 1);
@endif

isRootUser(int user_id) // returns true or false

fetchPermissions(int $status) // active = 1 or inactive = 0
// $status is optional if is empty all permissions will be fetched

fetchRoles(int $status) // active = 1 or inactive = 0
// $status is optional if is empty all roles will be fetched

fetchUserRoles(int $user_id)
// $user_id is id of the user from App\Models\User
bash
php artisan vendor:publish --tag="accesstree-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="accesstree-config"