register.blade.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. use App\Models\User;
  3. use Illuminate\Auth\Events\Registered;
  4. use Illuminate\Support\Facades\Auth;
  5. use Illuminate\Support\Facades\Hash;
  6. use Illuminate\Validation\Rules;
  7. use Livewire\Attributes\Layout;
  8. use Livewire\Volt\Component;
  9. new #[Layout('layouts.guest')] class extends Component
  10. {
  11. public string $name = '';
  12. public string $email = '';
  13. public string $password = '';
  14. public string $password_confirmation = '';
  15. /**
  16. * Handle an incoming registration request.
  17. */
  18. public function register(): void
  19. {
  20. $validated = $this->validate([
  21. 'name' => ['required', 'string', 'max:255'],
  22. 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
  23. 'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
  24. ]);
  25. $validated['password'] = Hash::make($validated['password']);
  26. event(new Registered($user = User::create($validated)));
  27. Auth::login($user);
  28. $this->redirect(route('dashboard', absolute: false), navigate: true);
  29. }
  30. }; ?>
  31. <div>
  32. <form wire:submit="register">
  33. <!-- Name -->
  34. <div>
  35. <x-input-label for="name" :value="__('Name')" />
  36. <x-text-input wire:model="name" id="name" class="block mt-1 w-full" type="text" name="name" required autofocus autocomplete="name" />
  37. <x-input-error :messages="$errors->get('name')" class="mt-2" />
  38. </div>
  39. <!-- Email Address -->
  40. <div class="mt-4">
  41. <x-input-label for="email" :value="__('Email')" />
  42. <x-text-input wire:model="email" id="email" class="block mt-1 w-full" type="email" name="email" required autocomplete="username" />
  43. <x-input-error :messages="$errors->get('email')" class="mt-2" />
  44. </div>
  45. <!-- Password -->
  46. <div class="mt-4">
  47. <x-input-label for="password" :value="__('Password')" />
  48. <x-text-input wire:model="password" id="password" class="block mt-1 w-full"
  49. type="password"
  50. name="password"
  51. required autocomplete="new-password" />
  52. <x-input-error :messages="$errors->get('password')" class="mt-2" />
  53. </div>
  54. <!-- Confirm Password -->
  55. <div class="mt-4">
  56. <x-input-label for="password_confirmation" :value="__('Confirm Password')" />
  57. <x-text-input wire:model="password_confirmation" id="password_confirmation" class="block mt-1 w-full"
  58. type="password"
  59. name="password_confirmation" required autocomplete="new-password" />
  60. <x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
  61. </div>
  62. <div class="flex items-center justify-end mt-4">
  63. <a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('login') }}" wire:navigate>
  64. {{ __('Already registered?') }}
  65. </a>
  66. <x-primary-button class="ms-4">
  67. {{ __('Register') }}
  68. </x-primary-button>
  69. </div>
  70. </form>
  71. </div>