Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude route from Laravel authentication

After running php artisan make:auth all the required routes are in the route.php file, but is it possible to remove one (I want to remove the register route)?

Currently I have

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

I know that Route::auth() is a shortcut to add all the routes. Should I specify the routes myself instead of using the shortcut?

like image 244
user2810895 Avatar asked Feb 01 '16 13:02

user2810895


2 Answers

Unfortunately you can't exclude register with the current implementation of Route::auth().

You would have to specify all the routes manually so

// Authentication Routes...
$this->get('login', 'Auth\AuthController@showLoginForm');
$this->post('login', 'Auth\AuthController@login');
$this->get('logout', 'Auth\AuthController@logout');

// 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');

I think this is a fairly common thing to want to do it would be nice if there was a parameter to the auth method to say without register maybe you could submit a pull-request to the project.

like image 74
Mark Davidson Avatar answered Sep 19 '22 17:09

Mark Davidson


In the new releases you can do it like so (in your web.php file):

Auth::routes(['register'=>false]);
like image 36
Enis P. Aginić Avatar answered Sep 20 '22 17:09

Enis P. Aginić