PHP code example of mbojanks / laravel-contextual-permissions

1. Go to this page and download the library: Download mbojanks/laravel-contextual-permissions 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/ */

    

mbojanks / laravel-contextual-permissions example snippets


use Mbojanks\ContextualPermissions\Traits\HasContextualRolesAndPermissions;

class User extends Authenticatable
{
    use HasRoles, HasContextualRolesAndPermissions;
}

$user->assignRoleInContext('school_manager', $school);

$user->hasRoleInContext('school_manager', $school);

$user->getPermissionsViaRolesInContext($school);

$user->getAllPermissionsInContext($school);

'locale' => 'sr',
'fallback_locale' => 'en',
bash
php artisan migrate
bash
php artisan permission:assign-context-role 1 teacher "App\Models\School" 3
bash
php artisan permission:check-context-role 1 teacher "App\Models\School" 3
bash
php artisan permission:list-context-roles 1 "App\Models\School" 3