'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.



Solution 1:[1]

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

// Authentication Routes...
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController@login');
Route::post('logout', 'Auth\LoginController@logout')->name('logout');
// Registration Routes...
Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController@register');

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

// Email Verification Routes...
Route::get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
Route::get('email/verify/{id}/{hash}', 'Auth\VerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController@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

Solution 2:[2]

To make it more complete, if you want to remove some Auth::routes, you can use something like this:

Auth::routes(['register' => false]);

Solution 3:[3]

it handles that via traits and comes up to YourProject\vendor\laravel\ui\src\AuthRouteMethods.phpthen to your YourProject\app\Http\Controllers\Auth\RegisterController.php where there is use RegistersUsers trait and then up to YourProject\vendor\laravel\ui\auth-backend\RegistersUsers.php But the changing package files' content of Laravel core is a bad practice. Its ok merely for tracing purpose of whats going on under the hood

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zahid hasan emon
Solution 2 seedme
Solution 3