Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Auth Register route in Laravel 8?

I need to disable my register route in Laravel 8. Tried

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

but the application threw up an error.

RuntimeException
In order to use the Auth::routes() method, please install the laravel/ui package.

If anyone points out what needs to change, will be grateful.

Thanks

like image 822
Debajeet Choudhury Avatar asked Oct 16 '20 05:10

Debajeet Choudhury


People also ask

How to disable register route in laravel 8?

laravel provide by us default Auth::routes() in my web. php file for login, register, forgot passwords routes but you can easily do it using “Auth::routes(['register' => false]);” to disable any routes such as register.

How to block register route in laravel?

in app/Http/Controller/Auth/RegisterController.php Show activity on this post. As of Laravel 5.7 you can pass an array of options to Auth::routes() . You can then disable the register routes with: Auth::routes(['register' => false]);

How to remove Auth route in laravel?

You can easily remove laravel standard authentication routes by setting false in your auth reference. E.g. Auth::routes(['register' => false]); . This also works for login , verify etc.


3 Answers

In addition, be sure to disable related routes, in routes/web.php :

Route::get('/register', function() {
    return redirect('/login');
});

Route::post('/register', function() {
    return redirect('/login');
});

I changed according feature tests in tests/Feature/RegistrationTest.php to try to keep work clean so I needed those redirections.

like image 192
Bastien Thouverez Avatar answered Oct 25 '22 02:10

Bastien Thouverez


At the end of my routes/web.php was the following line:

require __DIR__.'/auth.php';

In routes/auth.php are listed all additional routes for user login/register/logout. Just comment out or remove /register route from there.

like image 21
cakan Avatar answered Oct 25 '22 04:10

cakan


Laravel 8 uses fortify authentication. To disable registration from your laravel app, you need to disable it from fortify, which is located on /config/fortify.php

'features' => [
    // Features::registration(), // disable here
     Features::resetPasswords(),
     Features::emailVerification(),
     Features::updateProfileInformation(),
     Features::updatePasswords(),
     Features::twoFactorAuthentication(),
],
like image 35
sta Avatar answered Oct 25 '22 04:10

sta