Reputation: 4818
I have start working on laravel 5.4 , i have found that there is Auth::routes()
which is called default in web route. I want to more clear with the difference between Auth::routes()
and Route::auth()
.
Upvotes: 0
Views: 2117
Reputation: 5083
Route::auth()
will create the following routes (as found in Illuminate\Routing\Router.php
:
/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public function auth()
{
// 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');
}
Auth::routes()
will call the following function (as found in Illuminate\Support\Facades\Auth.php
):
/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public static function routes()
{
static::$app->make('router')->auth();
}
As you can see, the second method creates an instance of the first Router
class and calls the auth()
function on it. In the end there is no difference in the two methods. If you have a choice I would personally advice using Route::auth()
since that seems to be the "default" implementation.
Upvotes: 1
Reputation: 2723
Using Auth::routes()
or Route::auth()
is equivalent. Infact Auth::routes()
is defined as:
/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public static function routes()
{
static::$app->make('router')->auth();
}
where $app->make('router')
returns an Illuminate\Routing\Router
instance just like the facade Route
does.
Upvotes: 4