In your application, If you need to create different views for login form and show them in different URL(In case your app has multiple login points) you will need to write some of the routes of your own. A case can be having one registration form for ‘Buyers’ and a different registration form with completely different design and post-processing for ‘Showp owners’. A smart way of doing that would be to find the Auth routes that Laravel provides, copy them put new route URL/name as you need and assign your custom controller methods to handle them.
Most of us who use Laravel’s out of the box authentication, rarely need to look inside the set of available routes and where they are actually written. These routes can be found in
vendor/laravel/framework/src/Illuminate/Routing/Router.php
There are a bunch of functions that groups the routes involved in authentication.
/**
* Register the typical authentication routes for an application.
*
* @param array $options
* @return void
*/
public function auth(array $options = [])
{
// Authentication Routes...
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
$this->post('logout', 'Auth\LoginController@logout')->name('logout');
// Registration Routes...
if ($options['register'] ?? true) {
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');
}
// Password Reset Routes...
if ($options['reset'] ?? true) {
$this->resetPassword();
}
// Email Verification Routes...
if ($options['verify'] ?? false) {
$this->emailVerification();
}
}
/**
* Register the typical reset password routes for an application.
*
* @return void
*/
public function resetPassword()
{
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');
}
/**
* Register the typical email verification routes for an application.
*
* @return void
*/
public function emailVerification()
{
$this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
$this->get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
$this->get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
}
So, if you need to create your own set of routes, views and controllers you need pick which routes you might need.
Login/Logout
- GET login – to show the login form
- POST login – to post form data to this route which handles the actual login, creates a session, redirects etc.
- POST logout – to post a token/csrf to and do the logout process (destroy user session, redirect )
Register
- GET register- to show the registration form
- POST register- to post form data to this route which handles the actual registration, creates a user in DB, sends a verification email.
Reset password
- GET password/reset – Shows a form asking for username/email that requires a password reset.
- POST password/email – Handles the form submit and sends an email to the user where there is a temporary URL(with a token to identify the user) that takes the user to a password reset page where he can put a new password
- GET password/reset/{token} – Form to update password.
- POST password/rest – Handle the password reset form submission.
Email verification
By default, Laravel allows login of a un-verified user. Which means we need to restrict access of such user by applying a verified
middleware in the route/controller. Check this
https://laravel.com/docs/5.8/verification
- GET email/verify – Show a notice/Message saying that a verification link has been sent.
- GET email/verify/{id} – When a user visits this URL email is verified and the user is shown a confirmation message and asked to log in.
- GET email/verify/resend –
So it seems you will need these 9 routes if you want to set up your custom forms.
In addition to above, you may need to write social-login routes if you are using the additional sign in options with Facebook, Google etc. Look at Socialite