public function store(Requests\StoreUserRequest $request, $user_id = null) { $user = Users::findOrNew($user_id); $user->email = $request->get('email'); $user->name = $request->get('name'); $user->role = $request->get('role'); $password = trim($request->get('password')); if ($password != '') { $user->password = $request->get('password'); Notifications::add('Password changed', 'success'); } else { Notifications::add('Password not changed', 'warning'); } $user->active = $request->has('active'); $user->save(); Notifications::add('User saved', 'success'); return redirect()->route('root-users'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(StoreUserRequest $request) { // get the current user record $user = new User(); // update name and email addr $user->first_name = $request->input('first_name'); $user->last_name = $request->input('last_name'); $user->email = $request->input('email'); $user->save(); // prepare success message $message = 'User with id "' . $user->id . '" added'; // create list of instruments $instruments = Instrument::all(); // which instrument was assigned in the form? foreach ($instruments as $instrument) { if ($request->has(str_replace(' ', '_', $instrument->name))) { $user->assignInstrument($instrument); } else { $user->removeInstrument($instrument); } } // get list of possible user roles $roles = Role::all(); // which role was assigned in the form? foreach ($roles as $role) { if ($request->has(str_replace(' ', '_', $role->name))) { $user->assignRole($role); } else { $user->removeRole($role); } } return \Redirect::route($this->view_all_idx)->with(['status' => $message]); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(StoreUserRequest $request, $id) { if (Gate::denies('update', User::class)) { abort(403); } $record = User::find($id); if ($request->has('password')) { $record->update(['group_id' => $request->group_id, 'role' => $request->role, 'name' => $request->name, 'email' => $request->email, 'password' => bcrypt($request->password)]); } else { $record->update(['group_id' => $request->group_id, 'role' => $request->role, 'name' => $request->name, 'email' => $request->email]); } return redirect('/user')->with('alert-info', 'The record has been updated!'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(StoreUserRequest $request, $id) { if (Gate::denies('update', User::class)) { abort(403); } $record = User::find($id); $file_name = $record->document; if ($request->hasFile('document')) { if ($file_name != '') { if (Storage::disk('user')->has($file_name)) { Storage::disk('user')->delete($file_name); } } $file_name = str_random(32) . '.' . $request->file('document')->getClientOriginalExtension(); Storage::disk('user')->put($file_name, file_get_contents($request->file('document')->getRealPath())); } if ($request->has('password')) { $record->update(['parish_id' => $request->parish_id, 'role' => $request->role, 'name' => $request->name, 'email' => $request->email, 'password' => bcrypt($request->password)]); } else { $record->update(['parish_id' => $request->parish_id, 'role' => $request->role, 'name' => $request->name, 'email' => $request->email]); } return redirect('/user')->with('alert-info', 'The record has been updated!'); }