Auth Register Page
This document provides necessary information about the register.blade.php
file. The file is utilized for user registration purposes and is responsible for validating the inputs and handling the creation of a new user.
The code starts by importing necessary libraries and then sets initial states for user credentials (name
, email
, password
and passwordConfirmation
). It then presents the rules for validating these credentials. The actual process of registration is inside a function:
- First, the inputs are validated.
- Then a new user is created using the provided data.
- A new Registered event is triggered which can be listened to perform actions upon new user registration.
- After registration, the user is immediately logged in and redirected to the home page.
Lastly, a user-friendly form is rendered for new users to fill out and register.
<?php
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Auth\Events\Registered;
use function Laravel\Folio\{middleware};
use function Livewire\Volt\{state, rules};
middleware(['guest']);
state(['name' => '', 'email' => '', 'password' => '', 'passwordConfirmation' => '']);
rules([
'name' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required|min:8|same:passwordConfirmation',
]);
$register = function () {
$this->validate();
$user = User::create([
'email' => $this->email,
'name' => $this->name,
'password' => Hash::make($this->password),
]);
event(new Registered($user));
Auth::login($user, true);
return redirect()->intended('/');
}
?>
Parameter | Rules |
---|---|
name | required |
required, valid email, must be unique in the users table | |
password | required, minimum 8 characters, must be the same as passwordConfirmation |
The form rendered for user registration includes the following inputs:
- Name
- Email address
- Password
- Confirm Password
Each input field is linked with the wire:model
directive to its corresponding state in the Livewire component.
Register button is provided at the end to submit the form.
This code references a pull request for the Laravel Folio package to add event based routes. More information can be found at this link: