Skip to content

Commit 3eb9654

Browse files
committed
fix:add _method in useForm to keep using PATCH on routes and POST in Frontend spoofing as PATCH
1 parent 3aa2348 commit 3eb9654

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

app/Http/Controllers/Settings/ProfileController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ public function edit(Request $request): Response
2828
/**
2929
* Update the user's profile information.
3030
*/
31-
public function update(ProfileUpdateRequest $request): RedirectResponse
31+
public function update(Request $request): RedirectResponse
3232
{
3333
$user = $request->user();
3434

35-
$user->fill($request->only(['name', 'email']));
35+
$user->fill($request->validated());
36+
37+
if ($user->isDirty('email')) {
38+
$user->email_verified_at = null;
39+
}
3640

3741
if ($request->hasFile('profile_photo')) {
38-
// delete old avatar if exists
3942
if ($user->profile_photo_path && Storage::exists($user->profile_photo_path)) {
4043
Storage::delete($user->profile_photo_path);
4144
}
4245

43-
// save new avatar
4446
$path = $request->file('profile_photo')->store('avatars', 'public');
4547
$user->profile_photo_path = $path;
46-
} else {
47-
$user->profile_photo_path = null;
4848
}
4949

5050
$user->save();

app/Models/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class User extends Authenticatable
3636
'profile_photo_path',
3737
];
3838

39+
/**
40+
* The attributes that should be cast.
41+
*
42+
* @var array<string, string>
43+
*/
3944
protected $appends = [
4045
'avatar',
4146
];

resources/js/pages/settings/Profile.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const form = useForm({
5050
name: user.name,
5151
email: user.email,
5252
profile_photo: null as File | null,
53+
_method: 'PATCH',
5354
});
5455
5556
const handleAvatarChange = (event: Event) => {
@@ -96,7 +97,7 @@ const avatarSrc = computed(() => {
9697
<div class="group relative">
9798
<label for="avatar-upload" class="cursor-pointer" aria-label="Upload avatar">
9899
<Avatar size="lg">
99-
<AvatarImage :src="avatarSrc || user.avatar" alt="User avatar" />
100+
<AvatarImage :src="avatarSrc || user.avatar || ''" alt="User avatar" />
100101
<AvatarFallback>{{ getInitials(user.name) }}</AvatarFallback>
101102
</Avatar>
102103
</label>

routes/settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Route::redirect('settings', '/settings/profile');
1010

1111
Route::get('settings/profile', [ProfileController::class, 'edit'])->name('profile.edit');
12-
Route::post('settings/profile', [ProfileController::class, 'update'])->name('profile.update');
12+
Route::patch('settings/profile', [ProfileController::class, 'update'])->name('profile.update');
1313
Route::delete('settings/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
1414

1515
Route::get('settings/password', [PasswordController::class, 'edit'])->name('password.edit');

0 commit comments

Comments
 (0)