Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

UpdateUserProfileInformation.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Actions\Fortify;
  3. use App\Models\User;
  4. use Illuminate\Contracts\Auth\MustVerifyEmail;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Validation\Rule;
  7. use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
  8. class UpdateUserProfileInformation implements UpdatesUserProfileInformation
  9. {
  10. /**
  11. * Validate and update the given user's profile information.
  12. *
  13. * @param array<string, string> $input
  14. */
  15. public function update(User $user, array $input): void
  16. {
  17. Validator::make($input, [
  18. 'name' => ['required', 'string', 'max:255'],
  19. 'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
  20. 'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
  21. ])->validateWithBag('updateProfileInformation');
  22. if (isset($input['photo'])) {
  23. $user->updateProfilePhoto($input['photo']);
  24. }
  25. if ($input['email'] !== $user->email &&
  26. $this->userMustVerifyEmail()) {
  27. $this->updateVerifiedUser($user, $input);
  28. } else {
  29. $user->forceFill([
  30. 'name' => $input['name'],
  31. 'email' => $input['email'],
  32. ])->save();
  33. }
  34. }
  35. /**
  36. * Determine if the user must verify their email address.
  37. */
  38. protected function userMustVerifyEmail(): bool
  39. {
  40. return in_array(MustVerifyEmail::class, class_implements(User::class));
  41. }
  42. /**
  43. * Update the given verified user's profile information.
  44. *
  45. * @param array<string, string> $input
  46. */
  47. protected function updateVerifiedUser(User $user, array $input): void
  48. {
  49. $user->forceFill([
  50. 'name' => $input['name'],
  51. 'email' => $input['email'],
  52. 'email_verified_at' => null,
  53. ])->save();
  54. $user->sendEmailVerificationNotification();
  55. }
  56. }