mirror of
https://github.com/brufdev/many-notes.git
synced 2026-05-25 04:39:07 -05:00
42 lines
1.0 KiB
PHP
42 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Forms;
|
|
|
|
use Livewire\Form;
|
|
use App\Models\User;
|
|
use Illuminate\Validation\Rules;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Auth\Events\Registered;
|
|
|
|
class RegisterForm extends Form
|
|
{
|
|
public string $name = '';
|
|
|
|
public string $email = '';
|
|
|
|
public string $password = '';
|
|
|
|
public string $password_confirmation = '';
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
|
|
'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Handle an incoming registration request.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$validated = $this->validate();
|
|
$validated['password'] = Hash::make($validated['password']);
|
|
event(new Registered($user = User::create($validated)));
|
|
Auth::login($user);
|
|
}
|
|
}
|