Auth::user()]); } public function update(UpdateUserRequest $request, User $user): RedirectResponse { $data = collect($request->safe()->only([ 'name', 'email', 'password', ]))->reject(fn ($attr): bool => is_null($attr))->toArray(); $currentEmail = $user->email; $currentPassword = $request->validated('currentPassword'); if (isset($data['email']) && $data['email'] !== $currentEmail) { $otp = OtpController::generate(); OtpVerificationToken::updateOrInsert( ['email' => $currentEmail], [ 'token' => Hash::make($otp), 'payload' => Crypt::encrypt($data), 'created_at' => now(), ], ); $user->notify(new EmailUpdated($data['email'], $otp)); return to_route('otp.show', $user->id)->with([ 'info' => 'An otp has been sent to your registered email address', ]); } if ($currentPassword && ! Hash::check($currentPassword, $user->password)) { return to_route('profile.edit')->with([ 'error' => 'Wrong password provided!', 'askPassword' => true, ]); } $user->update($data); return to_route('profile.edit')->with(['success' => 'Profile updated successfully!']); } }