1. Go to this page and download the library: Download yaroslavmolchan/rbac 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/ */
use \YaroslavMolchan\Rbac\Models\Role;
$adminRole = Role::find(1);
$adminRole->attachPermission($createPermission);
//or you can insert only id
$adminRole->attachPermission($createPermission->id);
use \YaroslavMolchan\Rbac\Models\Role;
$adminRole = Role::find(1);
$adminRole->detachPermission($createPermission);
//or you can insert only id
$adminRole->detachPermission($createPermission->id);
use \YaroslavMolchan\Rbac\Models\Role;
$adminRole = Role::find(1);
$adminRole->attachPermissions([$createPermission, $removePermission]);
//or you can insert only id
$adminRole->detachPermission([$createPermission->id, $removePermission->id]);
use \YaroslavMolchan\Rbac\Models\Role;
$adminRole = Role::find(1);
$adminRole->detachPermissions([$createPermission, $removePermission]);
//or you can insert only id
$adminRole->detachPermissions([$createPermission->id, $removePermission->id]);
use App\User;
$user = User::find(1);
if ($user->canDo('product.create')) {
}
use \YaroslavMolchan\Rbac\Models\Permission;
$createPermission = Permission::find(1);
$productManagementPermissionGroup->attachPermission($createPermission);
//or you can insert only id
$productManagementPermissionGroup->attachPermission($createPermission->id);
use \YaroslavMolchan\Rbac\Models\Permission;
$createPermission = Permission::find(1);
$productManagementPermissionGroup->detachPermission($createPermission);
//or you can insert only id
$productManagementPermissionGroup->detachPermission($createPermission->id);
use \YaroslavMolchan\Rbac\Models\Role;
$adminRole = Role::find(1);
$adminRole->attachGroup($productManagementPermissionGroup);
use \YaroslavMolchan\Rbac\Models\Role;
$adminRole = Role::find(1);
$adminRole->detachGroup($productManagementPermissionGroup);
@ifUserIs('admin')
// show content only for admin
@else
// show content for other roles
@endif
@ifUserCan('product.create')
// show product create content
@endif
$ php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.