public function addRoles($id, array $roles)
 {
     $model = $this->find($id);
     foreach ($roles as $v) {
         $model->roles()->save($this->roleRepository->find($v));
     }
     return $model;
 }
예제 #2
0
 /**
  * Setup the required filters necessary for executing a role search request, based on the $input provided.
  *
  * @param array $input
  * @return mixed
  */
 public function fromInput(array $input = [])
 {
     $filterCollection = new SearchFilterCollection();
     $filterCollection->add(new IncludeFilter('owner', 'domains'));
     if (isset($input['keywords'])) {
         $filterCollection->add(KeywordFilter::fromKeywords($input['keywords']));
     }
     $filterCollection->add(OrderFilter::byInput($input));
     $accounts = $this->accountRepository->getByFilters($filterCollection);
     return $accounts;
 }
 /**
  * Edit a user
  * 
  * @return json
  */
 public function edit()
 {
     $data = Input::all();
     // Check if user is trying to disable their own account
     if ($data['id'] == Auth::user()->id && $data['edit']['state'] == 0) {
         return $this->jsonResponse(400, false, 'You cannot disable your own account.');
     }
     $user = $this->users->edit($data['id'], ['enabled' => $data['edit']['state']]);
     $roles = $this->roles->getBy('name', 'guest', '!=');
     foreach ($roles as $role) {
         $this->users->removeRole($user, $role);
     }
     foreach ($data['edit']['role'] as $role) {
         $this->users->assignRole($user, $role['id']);
     }
     return $this->jsonResponse(200, true, 'Successfully updated the user!', $this->users->getWithRoles($data['id']));
 }