$page_number ]); } /** * @param int $id * @return View|Factory|Application * @throws \Exception */ public function actionView(int $id): View|Factory|Application { $user = User::find($id); if (!$user) { // throw new NotFoundHttpException(); throw new \Exception('User not found'); } return view('user.view', [ 'user' => User::find($id) ]); } public function actionCreate(): View|Factory|Application { return view('user.form'); } public function actionStore(UserRequest $request): View|Factory|Application { $validated = $request->validated(); $user = new User(); $user->username = $validated['username']; $user->email = $validated['email']; $user->password_hash = Hash::make($validated['password']); $user->save(); return view('user.view', [ 'user' => User::find($user->id) ]); } /** * @throws \Exception */ public function actionUpdate(int $id): View|Factory|Application { $user = User::find($id); if (!$user) { throw new \Exception('User not found'); } return view('user.form', [ 'model' => $user ]); } /** * @throws \Exception */ public function actionEdit(int $id, FormRequest $request): View|Factory|Application { $user = User::find($id); if (!$user) { throw new \Exception('User not found'); } $request = UserRequest::rulesForUpdate($request, $user); $validated = $request->validated(); $user->username = $validated['username']; $user->email = $validated['email']; if (isset($validated['password'])) { $user->password_hash = Hash::make($validated['password']); } $user->save(); return view('user.view', [ 'user' => $user ]); } public function actionDelete(int $id): Application|\Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse { $user = User::find($id); if (!$user) { throw new \Exception('User not found'); } $user->delete(); return redirect('/admin/user'); } }