2023-07-06 10:48:32 +06:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Private;
|
|
|
|
|
2023-07-07 00:07:19 +06:00
|
|
|
use App\Http\Requests\Private\Profile\UpdateRequest;
|
|
|
|
use App\Services\Private\ProfileService;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
2023-07-06 10:48:32 +06:00
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
final class ProfileController extends Controller
|
|
|
|
{
|
2023-07-07 00:07:19 +06:00
|
|
|
public function __construct(
|
|
|
|
private readonly ProfileService $profileService
|
|
|
|
) { }
|
|
|
|
|
|
|
|
public function profile(Request $request): View
|
2023-07-06 10:48:32 +06:00
|
|
|
{
|
|
|
|
return view('private/profile/profile', [
|
2023-07-07 00:07:19 +06:00
|
|
|
'user' => $request->user()
|
2023-07-06 10:48:32 +06:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-07-07 00:07:19 +06:00
|
|
|
public function settings(Request $request): View
|
2023-07-06 10:48:32 +06:00
|
|
|
{
|
|
|
|
return view('private/profile/settings', [
|
2023-07-07 00:07:19 +06:00
|
|
|
'user' => $request->user()
|
2023-07-06 10:48:32 +06:00
|
|
|
]);
|
|
|
|
}
|
2023-07-07 00:07:19 +06:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2023-07-06 10:48:32 +06:00
|
|
|
}
|