/** * 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'])); }