/**
  * Process the flow of creating a new user
  *
  * @return \Illuminate\Database\Eloquent\Model|mixed
  * @throws \Exception
  */
 protected function doCreate()
 {
     try {
         $this->repoWrapper->begin();
         $createdUser = $this->userRepo->createRaw($this->getUserData());
         $createdUser = $this->addCommandRolesToUser($createdUser);
         $createdUser = $this->addCommandCategoriesToUser($createdUser);
     } catch (\Exception $e) {
         $this->repoWrapper->failure();
         throw $e;
     }
     $this->repoWrapper->end();
     return $createdUser;
 }
 /**
  * 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);
     }
 }
 /**
  * Do Update
  *
  * @throws \Exception
  * @return User
  */
 protected function doUpdate()
 {
     // As we don't want to do incomplete jobs here
     // we wrap the repository code so we can trace it for rollbacking
     // In this case RepoWrapperInterface has been bound to a class
     // that uses database transactions fo this feature.
     $userData = $this->getUserData();
     // get data that fits user repository for update
     $userId = $userData['id'];
     unset($userData['id']);
     // unset user id because it is not in mass assignment of the model
     try {
         $this->repoWrapper->begin();
         $updated = $this->userRepo->updateById($userId, $userData);
         $updated = $this->addCommandRolesToUser($updated);
         $updated = $this->addCommandCategoriesToUser($updated);
     } catch (\Exception $e) {
         $this->repoWrapper->failure();
         throw $e;
     }
     $this->repoWrapper->end();
     return $updated;
 }
Example #4
0
 /**
  * Set user by id
  *
  * @param $id
  * @return $this
  */
 public function setUserById($id)
 {
     $user = $this->userRepo->findById($id);
     return $this->setUser($user);
 }
 /**
  * Get users from repository
  *
  * @return mixed
  */
 protected function getUsers()
 {
     return $this->userRepo->getPaginated(50);
 }
 /**
  * Create admin user
  *
  * @return \Illuminate\Database\Eloquent\Model
  */
 private function createUser()
 {
     $user = $this->userRepo->createRaw(['user_name' => $this->ask('What is admin`s username? ', 'bigsinoos'), 'password' => Hash::make($this->ask('What is admin`s password? ', '1q2w3e')), 'email' => $this->ask('What is admin`s email? ', '*****@*****.**'), 'name' => $this->ask('What is admin`s name? ', 'Reza Shadman')]);
     return $user;
 }