/** * @param UpdateUserRequest $request * @param UserEntity $entity * @return $this|\Illuminate\Http\RedirectResponse */ public function update(UpdateUserRequest $request, UserEntity $entity) { if ($this->user->email !== $request->get('email')) { $this->validate($request, ['email' => 'unique:app_users,email']); } DB::beginTransaction(); try { $this->user->name = $request->get('name'); $this->user->email = $request->get('email'); if ($request->has('password')) { $this->validate($request, ['password' => 'required|confirmed|min:6']); $this->user->password = bcrypt($request->get('password')); } $this->user->save(); $this->updateEntry($entity->getEntity()->id, $this->user->id, ['input' => $request->all()]); DB::commit(); SweetAlert::success('Se ha editado su perfil', 'Excelente!')->autoclose(3500); } catch (EntryValidationException $e) { DB::rollBack(); return back()->withInput($request->all())->withErrors($e->getErrors()); } return redirect()->route('me.edit'); }
/** * Update a user * @param UpdateUserRequest $request * @param $uuid * @return $this|\Illuminate\Http\RedirectResponse */ public function update(UpdateUserRequest $request, UserEntity $entity, $uuid) { $user = User::byUuid($uuid)->firstOrFail(); if ($user->email !== $request->get('email')) { $this->validate($request, ['email' => 'unique:app_users,email']); } DB::beginTransaction(); try { $user->name = $request->get('name'); $user->email = $request->get('email'); if ($request->has('active')) { $user->active = $request->get('active'); } if ($request->has('password')) { $this->validate($request, ['password' => 'required|confirmed|min:6']); $user->password = bcrypt($request->get('password')); } $user->save(); if ($request->has('roles')) { $user->roles()->sync($request->get('roles')); } else { $user->roles()->sync([]); } $this->updateEntry($entity->getEntity()->id, $user->id, ['input' => $request->all()]); DB::commit(); SweetAlert::success('Se ha editado el Usuario', 'Excelente!')->autoclose(3500); } catch (EntryValidationException $e) { DB::rollBack(); return back()->withInput($request->all())->withErrors($e->getErrors()); } return redirect()->route('users.index'); }
/** * update a user with the data from the edit form * @param UpdateUserRequest $req [description] * @param User $user [description] * @return \Illuminate\Support\Facades\Redirect [description] */ public function update(UpdateUserRequest $req, User $user) { $user->fill($req->except('password')); if ($user->type != 'admin') { return redirect()->route('welcome'); } if (!empty($req->input('password'))) { $user->password = bcrypt($req->input('password')); } $user->save(); // sync roles with user $user->detachAllRoles(); if ($req->has('role')) { foreach ($req->input('role') as $role) { $user->attachRole($role); } } $this->processPermissions($user); $message = trans('users::users.update_success', ['name' => $user->name]); if (request('submit') == 'save') { return redirect()->back()->with('success', $message); } return redirect()->route('users.index')->with('success', $message); }
/** * update a user with the data from the edit form * @param UpdateUserRequest $req [description] * @param User $user [description] * @return \Illuminate\Support\Facades\Redirect [description] */ public function update(UpdateUserRequest $req, User $user) { $user->fill($req->all()); if ($user->type != 'admin') { return redirect()->route('welcome'); } if (!empty($req->input('password'))) { $user->password = bcrypt($req->input('password')); } $user->save(); $this->processPermissions($user); $message = trans('users::users.update_success', ['name' => $user->name]); if (request('submit') == 'save') { return redirect()->back()->with('success', $message); } return redirect()->route('users.index')->with('success', $message); }