Skip to content
Advertisement

Laravel routes/web.php how does Auth::routes() calls register/login/home page?

I am very new to laravel, still learning how the framework works.

I installed laravel Auth following this to tutorial https://laravel.com/docs/6.x/authentication

It created few views and controllers, as well as modified the web.php

My question is that im not being able to get my head around on how Auth::routes points to these url mysite.com/register, mysite.com/login.

From every tutorial I have going through, in order to specify a url you need to add it to web.php. so for example if I want to connect to contact-us in this url mysite.com/contact-us, I will have to alter my web.php to something like:

Route::post('contact-us', 'MyController@MyFunction');

But when I installed Laravel Auth, it just added this to my web.php:

Auth::routes();

This Auth::routes(); allows me to connect to mysite.com/register, mysite.com/login. How does it do it?

This is the default installation progress for Laravel 6, so i will not post any code regarding the above, as I believe anyone with a lot of experience knows what I am talking about.

Advertisement

Answer

Auth::routes() is the shorthand for the following routes.

// Authentication Routes...
Route::get('login', 'AuthLoginController@showLoginForm')->name('login');
Route::post('login', 'AuthLoginController@login');
Route::post('logout', 'AuthLoginController@logout')->name('logout');
// Registration Routes...
Route::get('register', 'AuthRegisterController@showRegistrationForm')->name('register');
Route::post('register', 'AuthRegisterController@register');

// Password Reset Routes...
Route::get('password/reset', 'AuthForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/email', 'AuthForgotPasswordController@sendResetLinkEmail')->name('password.email');
Route::get('password/reset/{token}', 'AuthResetPasswordController@showResetForm')->name('password.reset');
Route::post('password/reset', 'AuthResetPasswordController@reset');

// Email Verification Routes...
Route::get('email/verify', 'AuthVerificationController@show')->name('verification.notice');
Route::get('email/verify/{id}/{hash}', 'AuthVerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'AuthVerificationController@resend')->name('verification.resend');

So either you can use the above routes in your web.php file or you can use the shorthand helper function for those routes. you can check this link for more understanding about routing in laravel

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement