/** * Validate and save edited user data from edit form. * * @author [A. Gianotto] [<*****@*****.**>] * @since [v1.0] * @param int $id * @return Redirect */ public function postEdit(UpdateUserRequest $request, $id = null) { // We need to reverse the UI specific logic for our // permissions here before we update the user. $permissions = $request->input('permissions', array()); app('request')->request->set('permissions', $permissions); // Only update the email address if locking is set to false if (config('app.lock_passwords')) { return redirect()->route('users')->with('error', 'Denied! You cannot update user information on the demo.'); } try { // Get the user information $user = User::find($id); if (!Company::isCurrentUserHasAccess($user)) { return redirect()->route('users')->with('error', trans('general.insufficient_permissions')); } } catch (UserNotFoundException $e) { // Prepare the error message $error = trans('admin/users/message.user_not_found', compact('id')); // Redirect to the user management page return redirect()->route('users')->with('error', $error); } // First handle anything exclusive to editing. if ($request->has('groups')) { $user->groups()->sync($request->input('groups')); } else { $user->groups()->sync(array()); } // Do we want to update the user password? if ($request->has('password')) { $user->password = bcrypt($request->input('password')); } if ($request->has('username')) { $user->username = e($request->input('username')); } $user->email = e($request->input('email')); // Update the user $user->first_name = e($request->input('first_name')); $user->last_name = e($request->input('last_name')); $user->locale = e($request->input('locale')); $user->employee_num = e($request->input('employee_num')); $user->activated = e($request->input('activated', $user->activated)); $user->jobtitle = e($request->input('jobtitle')); $user->phone = e($request->input('phone')); $user->location_id = e($request->input('location_id')); $user->company_id = e(Company::getIdForUser($request->input('company_id'))); $user->manager_id = e($request->input('manager_id')); $user->notes = e($request->input('notes')); $user->permissions = json_encode($request->input('permission')); if ($user->manager_id == "") { $user->manager_id = null; } if ($user->location_id == "") { $user->location_id = null; } if ($user->company_id == "") { $user->company_id = null; } // Was the user updated? if ($user->save()) { // Prepare the success message $success = trans('admin/users/message.success.update'); // Redirect to the user page return redirect()->route('users')->with('success', $success); } return redirect()->back()->withInput()->withErrors($user->getErrors()); }