/**
  * User update form
  *
  * @param $id
  * @return View
  */
 public function edit($id)
 {
     try {
         // @TODO Move this part to a sparate command
         $user = $this->userRepo->getUserWithRoles($id);
         $roles = $this->roleRepo->getAll();
         $userRoles = $user->roles->lists('id');
         $userCategories = $this->catRepo->getUserCategories($user)->lists('id');
         $categories = $this->catRepo->getAll();
         return $this->view('salgado.pages.user.create_edit', compact('user', 'roles', 'userRoles', 'userCategories', 'categories'));
     } catch (NotFoundException $e) {
         App::abort(404);
     }
 }
 /**
  * Bulk edit of states and roles
  *
  * @return View
  */
 public function getRoleStates()
 {
     $states = $this->stateRepo->getAllWithRoles();
     $roles = $this->roleRepo->getAll();
     $stateRoles = [];
     foreach ($states as $state) {
         $stateRoles[$state->id] = $state->roles->lists('name', 'id');
     }
     return $this->view('salgado.pages.state.role_state', compact('states', 'roles', 'stateRoles'));
 }
 /**
  * Add roles to user
  *
  * @param $user
  * @param array $roles
  */
 private function addRolesToUser($user, array $roles)
 {
     foreach ($roles as $role) {
         try {
             $repoRoll = $this->roleRepo->findByName($role);
         } catch (NotFoundException $e) {
             $repoRoll = $this->roleRepo->createRaw(['name' => $role]);
         }
         $this->roleRepo->addRoleToUser($user, $repoRoll);
     }
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return Role
  */
 public function handle($command)
 {
     return $this->roleRepo->updateById($command->id, (array) $command);
 }