150

Recently I start to use laravel 5.3 to write a blog, but I have a question after run php artisan make:auth

when I run this, it will generate routes in my web.php

this is the code in it:

Auth::routes();

Route::get('/home', 'HomeController@index');

Then I run php artisan route:list, I find lots of actions, like LoginController@login...

But I didn't find these actions in my App\Http\Controllers\Auth, where are these?

And also what is the Auth::routes() stand for, I can't find the routes about Auth.

I need someone help, thank you to answer my question

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
g1eny0ung
  • 1,761
  • 3
  • 14
  • 17
  • 20
    Am I the only one who now hates all those Laravel magics? – Muhammad Usman Sep 05 '18 at 08:24
  • 2
    I don't mind the laravel magics, if only they were documented... and worked consistently without having to walk widdershins around the server while chanting php artisan..what? – baradhili Jan 08 '19 at 00:47
  • Everything Laravel is not for developers, it's for companies and novice users who want to bring up new apps fast and easy, even their documentation. I'd still prefer Codeigniter if I had a choice. – BlackPanther Feb 13 '19 at 06:35
  • Read this guide: https://medium.com/@panjeh/laravel-auth-routes-email-verification-reset-password-authentication-registration-routes-fb82b3337150 – panjeh Mar 28 '19 at 17:56
  • @MuhammadUsman Talk about magic, now there's laravel jetstream... – Silidrone Oct 03 '20 at 08:47

14 Answers14

242

Auth::routes() is just a helper class that helps you generate all the routes required for user authentication. You can browse the code here https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php instead.

Here are the routes

// 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...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');

// Password Reset Routes...
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');
Kévin Bibollet
  • 3,573
  • 1
  • 15
  • 33
Lee
  • 3,044
  • 1
  • 12
  • 25
  • 3
    Thanks! I see the ../Routing/Router.php and now I know how the routes work.But where is the Auth static method routes()? I still can't find it, forgive me I am a laravel beginner... – g1eny0ung Aug 29 '16 at 02:59
  • 5
    Auth::routes method is here https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Auth.php and its calling the Router function anyway. Please mark this as answer if this have helped you, thanks. – Lee Aug 29 '16 at 03:25
  • 3
    `Auth` is a *facade* and will be defined in `config/app.php` You will find the class that acts as its provider in that configuration file. – Jason Aug 16 '17 at 15:12
  • Have same but getting error : `NotFoundHttpException in RouteCollection.php line 161:`, and another api's running fine. – 151291 Oct 26 '18 at 11:21
  • `$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');` not able to run `Auth` api's – 151291 Oct 26 '18 at 12:39
  • As of *5.7* you can also pass options to the Auth::routes() Like `Auth::routes(['register' => false]);` To disable register. The follow options are available `register`, `reset` and `verify`. https://github.com/laravel/framework/blob/5.7/src/Illuminate/Routing/Router.php#L1147 – Raldo94 Dec 17 '18 at 13:17
  • For Laravel 5.7 and 5.8 I suggest reading this guide: https://medium.com/@panjeh/laravel-auth-routes-email-verification-reset-password-authentication-registration-routes-fb82b3337150 – panjeh Jun 22 '19 at 18:16
  • I removed Auth::routes() and add those detailed routes. It is totally wasting my time to search a document for it. – Terry Lin Sep 17 '19 at 06:04
73

Here's Laravel 5.7, Laravel 5.8, Laravel 6.0, Laravel 7.0, and Laravel 8.0 (note a minor bc change in 6.0 to the email verification route).

// 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')->name('password.update');

// Confirm Password (added in v6.2)
Route::get('password/confirm', 'Auth\ConfirmPasswordController@showConfirmForm')->name('password.confirm');
Route::post('password/confirm', 'Auth\ConfirmPasswordController@confirm');

// 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'); // v6.x
/* Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify'); // v5.x */
Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');

You can verify these routes here:

zyglobe
  • 1,240
  • 1
  • 10
  • 15
  • 1
    There was indeed a small change from 5.8 to 6.x as your links show: The route for the email verification link should be `'email/verify/{id}/{hash}'`. Otherwise the hash can’t be verified and a 403 error will be thrown saying “This action is unauthorized”. – debite Sep 15 '19 at 12:51
47

Auth routes for Laravel 5.3 instead Auth::routes(). I hope it helps...

Route::group(['middleware' => ['web']], function() {

// Login Routes...
    Route::get('login', ['as' => 'login', 'uses' => 'Auth\LoginController@showLoginForm']);
    Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\LoginController@login']);
    Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\LoginController@logout']);

// Registration Routes...
    Route::get('register', ['as' => 'register', 'uses' => 'Auth\RegisterController@showRegistrationForm']);
    Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\RegisterController@register']);

// Password Reset Routes...
    Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\ForgotPasswordController@showLinkRequestForm']);
    Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\ForgotPasswordController@sendResetLinkEmail']);
    Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\ResetPasswordController@showResetForm']);
    Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\ResetPasswordController@reset']);
});

So if you change some names of these routes, remember to also change in views the actions of the posts!

Walter Pozzguo
  • 571
  • 3
  • 4
  • Thanks but you don't need to 'middleware' => ['web'] because of : out of the box, the web middleware group is automatically applied to your routes/web.php file by the RouteServiceProvider. – panjeh Mar 27 '19 at 15:23
  • @panjeh this appears to be true for the main `routes/web.php` file. However, for any such file in a vendor dir (ie. if you are trying to move the auth stuff into a package), you are required to add the web middleware yourself. – SlimDeluxe Aug 27 '20 at 06:43
15

For Laravel 5.5.x

// 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...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');

// Password Reset Routes...
$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');
Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97
9

function call order:

  1. (Auth)Illuminate\Support\Facades\Auth@routes (https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Auth.php)
  2. (App)Illuminate\Foundation\Application@auth
  3. (Route)Illuminate\Routing\Router

it's route like this:

public function auth()
{
    // Authentication Routes...
    $this->get('login', 'Auth\AuthController@showLoginForm');
    $this->post('login', 'Auth\AuthController@login');
    $this->get('logout', 'Auth\AuthController@logout');
    // Registration Routes...
    $this->get('register', 'Auth\AuthController@showRegistrationForm');
    $this->post('register', 'Auth\AuthController@register');
    // Password Reset Routes...
    $this->get('password/reset/{token?}', 'Auth\PasswordController@showResetForm');
    $this->post('password/email', 'Auth\PasswordController@sendResetLinkEmail');
    $this->post('password/reset', 'Auth\PasswordController@reset');
}
SilentCat
  • 99
  • 1
  • 2
  • https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php#L298 – Matt Kieran Dec 18 '16 at 14:48
  • This answer actually sheds light on the question asked by OP. Thanks @SilentCat. – Valentine Shi Mar 22 '19 at 05:17
  • I thought it would be good to verbally explain what happens in these 3 steps above: `Auth::routes()` - the Auth facade - retrieves the `Router` object instance from Laravel container and calls its pre-existing method `auth`. `auth` in turn defines the routes and their respective controllers that were generated by `php artisan make:auth`. This is it. – Valentine Shi Mar 22 '19 at 06:31
8

This worked for me with Laravel 5.6.

In the file web.php, just replace:

Auth::routes();

By:

//Auth::routes();
// Authentication Routes...
Route::get('admin/login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('admin/login', 'Auth\LoginController@login');
Route::post('admin/logout', 'Auth\LoginController@logout')->name('logout');
// 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');

And remove the Register link in the two files below:

welcome.blade.php
layouts/app.blade.php
DevonDahon
  • 7,460
  • 6
  • 69
  • 114
5

If you are searching these same routes for laravel 7 version you'll find it here Vendor/laravel/ui/src/AuthRouteMethods.php

Kunal Rajput
  • 664
  • 1
  • 7
  • 21
5

For Laravel 8:

use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\Auth\ForgotPasswordController;
use App\Http\Controllers\Auth\ConfirmPasswordController;
use App\Http\Controllers\Auth\VerificationController;

Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('login', [LoginController::class,'login']);
Route::post('logout',  [LoginController::class,'logout'])->name('logout');

// Registration Routes...
Route::get('register', [RegisterController::class, 'showRegistrationForm'])->name('register');
Route::post('register', [RegisterController::class, 'register']);

// Password Reset Routes...
Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request');
Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
Route::get('password/reset/{token}', [ForgotPasswordController::class, 'showResetForm'])->name('password.reset');
Route::post('password/reset', [ForgotPasswordController::class, 'reset'])->name('password.update');

// Confirm Password 
Route::get('password/confirm', [ConfirmPasswordController::class, 'showConfirmForm'])->name('password.confirm');
Route::post('password/confirm', [ConfirmPasswordController::class, 'confirm']);

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

// Home
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
just-Luka
  • 377
  • 1
  • 6
  • 19
4

if you are in laravel 5.7 and above Auth::routes(['register' => false]); in web.php

more possible options are as:

Auth::routes([
  'register' => false, // Routes of Registration
  'reset' => false,    // Routes of Password Reset
  'verify' => false,   // Routes of Email Verification
]);
bharat
  • 1,762
  • 1
  • 24
  • 32
1

I'm surprised nobody mentioned the command php artisan route:list, which gives a list of all registered app routes (including Auth::routes() and Passport::routes() if registered)

Shay
  • 2,060
  • 2
  • 16
  • 22
0

the loginuser class uses a trait called AuthenticatesUsers

if you open that trait you will see the functions (this applies for other controllers) Illuminate\Foundation\Auth\AuthenticatesUsers;

here is the trait code https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php

sorry for the bad format, im using my phone

also Auth::routes() it just calls a function that returns the auth routes thats it (i think)

Achraf Khouadja
  • 6,119
  • 4
  • 27
  • 39
  • Yes, i look through the Auth/ dir, but I am not find the method,like App\Http\Controllers\Auth\ResetPasswordController@showResetForm,where can I find the method after @, I cost much time to find it, but now I also can't find it..I am new to laravel.. – g1eny0ung Aug 29 '16 at 02:56
  • 1
    here is the full path `vendor\laravel\src\Illuminate\Foundation\Auth\ResetsPasswords` , if you want to change this or something , dont change this, just add the same method to ur controller and then change it, – Achraf Khouadja Aug 29 '16 at 04:13
  • @Achraf Khouadja, It seems you master laravel. I need you help. Look here : http://stackoverflow.com/questions/41047583/how-to-add-dynamic-dropdown-list-column-on-laravel-5-3-registration – moses toh Dec 09 '16 at 03:20
0

After I ran -composer require laravel/ui -php artisan ui:auth

I started seeing the classes in the Auth folder. Http/Controller/Auth

TimeToCodeTheRoad
  • 7,032
  • 16
  • 57
  • 70
0

In the Http/Controller/Auth you can find all the controllers regarding authentication. I was having issue redirect but then I made a new const in RouteServiceProvider.php under Http/Providers... And used it in my controllers to redirect to the page I want... protected $redirectTo = RouteServiceProvider::ADMIN;

0

Works for Laravel 10

use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\Auth\ForgotPasswordController;
use App\Http\Controllers\Auth\ConfirmPasswordController;
use App\Http\Controllers\Auth\VerificationController;

Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('login', [LoginController::class,'login']);
Route::post('logout',  [LoginController::class,'logout'])->name('logout');

// Registration Routes...
Route::get('register', [RegisterController::class, 'showRegistrationForm'])->name('register');
Route::post('register', [RegisterController::class, 'register']);

// Password Reset Routes...
Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request');
Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
Route::get('password/reset/{token}', [ForgotPasswordController::class, 'showResetForm'])->name('password.reset');
Route::post('password/reset', [ForgotPasswordController::class, 'reset'])->name('password.update');

// Confirm Password 
Route::get('password/confirm', [ConfirmPasswordController::class, 'showConfirmForm'])->name('password.confirm');
Route::post('password/confirm', [ConfirmPasswordController::class, 'confirm']);

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

Quickee
  • 321
  • 1
  • 6
  • 13