Multi-auth Mutltitrust (Controller)


Requirement

You can find Entrust and other packages which is helpful for roles and permission . but that are not active multi-auth system. Now time for Multi-Auth . Here Multitrust follow @jacurtis multi-auth system . so at first follow how implement multi-auth .

Roles master

Attaching, Detaching and Syncing Roles (user+admin)

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
use App\Admin;
use Code4mk\Multitrust\Models\Role;
$admin = Admin::find($id);
$admin->attachRole($adminRole); // you can pass whole object, or just an id
$admin->detachRole($adminRole); // in case you want to detach role
$admin->detachAllRoles(); // in case you want to detach all roles
$admin->syncRoles($roles); // you can pass Eloquent collection, or just an array of ids
use App\Admin;
use Code4mk\Multitrust\Models\Role;
public function update(Request $request, $id)
{
$admin = Admin::find($id);
$roles = $request->roles;
$admin->update();
$admin->attachRole($roles);
}

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

admins+permissions

use App\Admin;
use Code4mk\Multitrust\Models\Permission;
$admin = Admin::find($id);
$admin->attachPermission($deleteUsersPermission); // permission attached to a user
$admin->detachPermission($deleteUsersPermission);
$admin->detachAllPermissions();
$admin->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);
}