Single-auth Mutltitrust (Controller)


Roles master

Attaching, Detaching and Syncing Roles (user)

use App\User;
use Code4mk\Multitrust\Models\Role;
$user = User::find($id);
$user->attachRole($adminRole); // you can pass whole object, or just an id
$user->detachRole($adminRole); // in case you want to detach role
$user->detachAllRoles(); // in case you want to detach all roles
$user->syncRoles($roles); // you can pass Eloquent collection, or just an array of ids

Permissions master

users+permissions

use App\User;
use Code4mk\Multitrust\Models\Permission;
$user = User::find($userId);
$user->attachPermission($deleteUsersPermission); // permission attached to a user
$user->detachPermission($deleteUsersPermission);
$user->detachAllPermissions();
$user->syncPermissions($permissions); // you can pass Eloquent collection, or just an array of ids

roles+permissions

use Code4mk\Multitrust\Models\Role;
use Code4mk\Multitrust\Models\Permission;
$role = Role::find($roleId);
$role->attachPermission($createUsersPermission); // permission attached to a role
$role->detachPermission($createUsersPermission); // in case you want to detach permission
$role->detachAllPermissions(); // in case you want to detach all permissions
$role->syncPermissions($permissions); // you can pass Eloquent collection, or just an array of ids
use Code4mk\Multitrust\Models\Role;
use Code4mk\Multitrust\Models\Permission;
public function update(Request $request, $id)
{
$roles = Role::find($id);
$permission = $request->permission;
$roles->save();
$roles->attachPermission($permission);
}