/**
  * Attempt to remove the given role from this user.
  * returns true on success and false otherwise.
  *
  * @param RoleInterface $role
  * @throws UnkownRoleException
  * @return boolean
  */
 public function removeRole(RoleInterface $role)
 {
     $eloquent_role = $this->roles()->whereId($role->getId())->first();
     if (is_null($eloquent_role)) {
         throw new UnkownRoleException($this->getId() . '(' . $this->getName() . ') does not have the role ' . $role->getId() . '(' . $role->getName() . ')');
     }
     $success = $this->roles()->detach($role->getId());
     return $success;
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(RoleInterface $role, ResourceInterface $privilege, $action_id)
 {
     $response = Redirect::back();
     // find the action we are trying to give tot he role
     $action = null;
     foreach ($privilege->getActions() as &$check_action) {
         if ($check_action->getId() == $action_id) {
             $action = $check_action;
             break;
         }
     }
     if ($action) {
         $container = $action->getResource()->getName();
         // This decides which add permission bootstrap accordion is open upon load
         $response->with('permission_add_container_open', $container);
         // This decides which permission bootstrap accordion is open upon load
         $response->with('permission_container_open', $container);
         if ($role->addPermission($action, 0)) {
             $response->with('permission', trans('roles::permission.add success', ['representation' => $action->getResource()->getName() . '.' . $action->getName()]));
         } else {
             $errors = new MessageBag();
             $errors->add('permission', trans('roles::permission.add fail', ['representation' => $action->getResource()->getName() . '.' . $action->getName(), 'action_id' => $action_id]));
             $response->withErrors($errors);
         }
     } else {
         $errors = new MessageBag();
         $errors->add('permission', trans('roles::action.not found', ['action_id' => $action_id]));
         $response->withErrors($errors);
     }
     // Info to the edit view: open privilege tab of the accordion
     $response->with('privilege_open', true);
     return $response;
 }