File tree Expand file tree Collapse file tree 4 files changed +14
-8
lines changed
Http/Controllers/Settings
resources/js/pages/settings Expand file tree Collapse file tree 4 files changed +14
-8
lines changed Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff 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 ];
Original file line number Diff line number Diff 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
5556const 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 >
Original file line number Diff line number Diff line change 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 ' );
You can’t perform that action at this time.
0 commit comments