PHP code example of doc88 / flux-entity-permission

1. Go to this page and download the library: Download doc88/flux-entity-permission 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/ */

    

doc88 / flux-entity-permission example snippets

 
    composer 
     
    'providers' => [
        ...
        Doc88\FluxEntityPermission\FluxEntityPermissionServiceProvider::class,
    ]
 
    php artisan vendor:publish
 
    php artisan migrate
     
    use Doc88\FluxEntityPermission\Traits\HasEntityPermissions;

    class User {
        use HasEntityPermissions;
    }

    // Entities which the user has access to
    EntityPermission::list($user);

    // Specifying which entity you want to list
    EntityPermission::list($user, 'App\Company');

    /**
     * Return: array
    */

    // Ids of entities which the user has access to
    EntityPermission::idList($user, 'App\Company');

    /**
     * Return: array
    */

    // The entity you want to access
    $company = Company::find(1);
    
    // Checking if the user has access to the entity
    EntityPermission::has($user, $company);
    
    /**
    * Return: true or false
    */
    

    // The entity you want to access
    $company = Company::find(1);
    
    // Grants permission to the entity for the User
    EntityPermission::register($user, $company);
    
    /**
    * Return: true or false
    */

    // The entity you want to access
    $company = Company::find(1);
    
    // Revokes permission to the Entity
    EntityPermission::revoke($user, $company);

    /**
    * Return: true or false
    */
    

    $user = User::find(1);
    
    // Entities which the user has access to
    $user->listEntityAccess();

    // Specifying which entity you want to list
    $user->listEntityAccess('App\Company');

    /**
     * Return: array
    */

    $user = User::find(1);

    // The entity you want to access
    $company = Company::find(1);
    
    // Checking if the user has access to the entity
    $user->hasEntityAccess($company);
    
    /**
    * Return: true or false
    */
    

    $user = User::find(1);

    // The entity you want to access
    $company = Company::find(1);
    
    // Grants permission to the entity for the User
    $user->registerEntityAccess($company);
    
    /**
    * Return: true or false
    */
    
    $user = User::find(1);

    // The entity you want to access
    $company = Company::find(1);
    
    // Revokes permission to the entity
    $user->revokeEntityAccess($company);

    /**
    * Return: true or false
    */