App\Http\Controllers\Laralum\UsersController::setRoles PHP Метод

setRoles() публичный Метод

public setRoles ( $id, Illuminate\Http\Request $request )
$request Illuminate\Http\Request
    public function setRoles($id, Request $request)
    {
        Laralum::permissionToAccess('laralum.users.access');
        # Check permissions
        Laralum::permissionToAccess('laralum.users.roles');
        # Find the user
        $user = Laralum::user('id', $id);
        # Check if admin access
        Laralum::mustNotBeAdmin($user);
        # Get all roles
        $roles = Laralum::roles();
        # Change user's roles
        foreach ($roles as $role) {
            $modify = true;
            # Check for su
            if ($role->su) {
                $modify = false;
            }
            # Check if it's assignable
            if (!$role->assignable and !Laralum::loggedInUser()->su) {
                $modify = false;
            }
            if ($modify) {
                if ($request->input($role->id)) {
                    # The admin selected that role
                    # Check if the user was already in that role
                    if ($this->checkRole($user->id, $role->id)) {
                        # The user is already in that role, so no change is made
                    } else {
                        # Add the user to the selected role
                        $this->addRel($user->id, $role->id);
                    }
                } else {
                    # The admin did not select that role
                    # Check if the user was in that role
                    if ($this->checkRole($user->id, $role->id)) {
                        # The user is in that role, so as the admin did not select it, we need to delete the relationship
                        $this->deleteRel($user->id, $role->id);
                    } else {
                        # The user is not in that role and the admin did not select it
                    }
                }
            }
        }
        # Return Redirect
        return redirect()->route('Laralum::users')->with('success', trans('laralum.msg_user_roles_edited'));
    }