- Translated UI elements to Indonesian for better localization. - Improved layout by introducing Card components for better visual structure. - Removed unnecessary imports and props related to passkeys and two-factor authentication. - Updated tests to cover new password update scenarios and validation rules. - Ensured proper redirection and error handling for unauthorized access to security settings. - Enhanced user experience by adding success flash messages on password updates.
76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Settings;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Settings\ProfileUpdateRequest;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class ProfileController extends Controller
|
|
{
|
|
/**
|
|
* Show the user's profile settings page.
|
|
*/
|
|
public function edit(Request $request): Response
|
|
{
|
|
$user = $request->user();
|
|
$user->load('userProfile');
|
|
|
|
return Inertia::render('settings/profile', [
|
|
'user' => [
|
|
'id' => $user->id,
|
|
'email' => $user->email,
|
|
'username' => $user->username,
|
|
'userProfile' => $user->userProfile ? [
|
|
'full_name' => $user->userProfile->full_name,
|
|
'phone_number' => $user->userProfile->phone_number,
|
|
'gender' => $user->userProfile->gender?->value,
|
|
'birth_date' => $user->userProfile->birth_date?->format('Y-m-d'),
|
|
'address' => $user->userProfile->address,
|
|
] : null,
|
|
],
|
|
'mustVerifyEmail' => $user instanceof MustVerifyEmail,
|
|
'status' => $request->session()->get('status'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the user's profile information.
|
|
*/
|
|
public function update(ProfileUpdateRequest $request): RedirectResponse
|
|
{
|
|
$validated = $request->validated();
|
|
$user = $request->user();
|
|
|
|
$user->fill([
|
|
'email' => $validated['email'],
|
|
'username' => $validated['username'],
|
|
]);
|
|
|
|
if ($user->isDirty('email')) {
|
|
$user->email_verified_at = null;
|
|
}
|
|
|
|
$user->save();
|
|
|
|
$user->userProfile()->updateOrCreate(
|
|
[],
|
|
[
|
|
'full_name' => $validated['full_name'],
|
|
'phone_number' => $validated['phone_number'] ?? null,
|
|
'gender' => $validated['gender'] ?? null,
|
|
'birth_date' => $validated['birth_date'] ?? null,
|
|
'address' => $validated['address'] ?? null,
|
|
],
|
|
);
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => 'Profil berhasil diperbarui.']);
|
|
|
|
return to_route('profile.edit');
|
|
}
|
|
}
|