1. Go to this page and download the library: Download ordain/delegation 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/ */
ordain / delegation example snippets
use Ordain\Delegation\Contracts\DelegatableUserInterface;
use Ordain\Delegation\Traits\HasDelegation;
class User extends Authenticatable implements DelegatableUserInterface
{
use HasDelegation;
protected $fillable = [
// ... your fields
'can_manage_users',
'max_manageable_users',
'created_by_user_id',
];
}
use Ordain\Delegation\Facades\Delegation;
// Can this user assign a role to another user?
if (Delegation::canAssignRole($delegator, $role, $target)) {
Delegation::delegateRole($delegator, $target, $role);
}
// Can this user create new users?
if (Delegation::canCreateUsers($user)) {
// Create user...
}
// What roles can this user assign?
$assignableRoles = Delegation::getAssignableRoles($user);
use Ordain\Delegation\Domain\ValueObjects\DelegationScope;
// Define what a manager can delegate
$scope = new DelegationScope(
canManageUsers: true,
maxManageableUsers: 10,
assignableRoleIds: [1, 2, 3],
assignablePermissionIds: [4, 5],
);
Delegation::setDelegationScope($manager, $scope);