diff --git a/app/Dto/Request/Private/Profile/Update.php b/app/Dto/Request/Private/Profile/Update.php new file mode 100644 index 0000000..3ea10b4 --- /dev/null +++ b/app/Dto/Request/Private/Profile/Update.php @@ -0,0 +1,17 @@ +name; + } +} diff --git a/app/Http/Controllers/Private/Controller.php b/app/Http/Controllers/Private/Controller.php new file mode 100644 index 0000000..0d678f1 --- /dev/null +++ b/app/Http/Controllers/Private/Controller.php @@ -0,0 +1,13 @@ + Auth::user() + 'user' => $request->user() ]); } - public function settings(): View + public function settings(Request $request): View { return view('private/profile/settings', [ - 'user' => Auth::user() + 'user' => $request->user() ]); } + + public function update(UpdateRequest $request): RedirectResponse + { + $data = $request->getDto(); + $user = $request->user(); + + $result = $this->profileService->update($data, $user); + if ($result->isError()) { + return redirect()->back()->withInput()->withErrors($result->getMessage()); + } + return redirect()->route('profile.edit')->withSuccess($result->getMessage()); + } } diff --git a/app/Http/Requests/Private/Profile/UpdateRequest.php b/app/Http/Requests/Private/Profile/UpdateRequest.php new file mode 100644 index 0000000..8dcaadb --- /dev/null +++ b/app/Http/Requests/Private/Profile/UpdateRequest.php @@ -0,0 +1,25 @@ + ['required', 'max:255'], + ]; + } + + public function getDto(): Update + { + return new Update(name: $this->input('name')); + } +} diff --git a/app/Services/Private/ProfileService.php b/app/Services/Private/ProfileService.php new file mode 100644 index 0000000..080c090 --- /dev/null +++ b/app/Services/Private/ProfileService.php @@ -0,0 +1,31 @@ + $update->getName() + ]; + $this->userCommandHandler->handleUpdate($user, $data); + } catch (\Throwable $e) { + report($e->getMessage()); + return $this->errService($e->getMessage()); + } + return $this->ok(__('Profile saved successfully')); + } +} diff --git a/lang/en.json b/lang/en.json index b7e847e..803e73b 100644 --- a/lang/en.json +++ b/lang/en.json @@ -37,5 +37,12 @@ "Your Email": "Your Email", "Your Password": "Your Password", "Remember me": "Remember me", - "Sign in": "Sign in" + "Sign in": "Sign in", + "Toggle navigation": "Toggle navigation", + "Hello": "Hello", + "My Profile": "My Profile", + "Settings": "Settings", + "Dashboard": "Dashboard", + "Save": "Save", + "Profile saved successfully": "Profile saved successfully" } diff --git a/lang/ru.json b/lang/ru.json index 16231f6..8602520 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -37,5 +37,12 @@ "Your Email": "Ваш Email", "Your Password": "Ваш пароль", "Remember me": "Запомнить", - "Sign in": "Войти" + "Sign in": "Войти", + "Toggle navigation": "Переключение навигации", + "Hello": "Здравствуйте", + "My Profile": "Мой профиль", + "Settings": "Настройки", + "Dashboard": "Dashboard", + "Save": "Сохранить", + "Profile saved successfully": "Профиль успешно сохранен" } diff --git a/resources/views/private/profile/profile.blade.php b/resources/views/private/profile/profile.blade.php new file mode 100644 index 0000000..608c13a --- /dev/null +++ b/resources/views/private/profile/profile.blade.php @@ -0,0 +1,34 @@ +@section('meta_title', __('My Profile')) +@section('h1', __('My Profile')) + +
+
+
+
+
+ @csrf + @method('PUT') + + + + +
+
+
+
+
+
+
+
+
+ @csrf + @method('PUT') + + + + +
+
+
+
+
diff --git a/routes/web.php b/routes/web.php index daac5b0..48ce5e0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,6 +23,8 @@ Route::middleware(['auth', 'verified'])->group(function () { Route::prefix('profile')->as('profile.') ->group(function () { Route::get('/', [\App\Http\Controllers\Private\ProfileController::class, 'profile'])->name('edit'); + Route::put('/', [\App\Http\Controllers\Private\ProfileController::class, 'update'])->name('update'); + Route::put('password', [\App\Http\Controllers\Private\ProfileController::class, 'updatePassword'])->name('update-password'); Route::get('settings', [\App\Http\Controllers\Private\ProfileController::class, 'settings'])->name('settings'); }); });