17

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

Debajeet Choudhury
  • 389
  • 2
  • 5
  • 9

9 Answers9

22

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(),
],
STA
  • 30,729
  • 8
  • 45
  • 59
  • Hello good sir, how about making the path "login" unavailable too? Your answer helped me on the "/register" path, but by trying the same approach to the "login" path it throws me QueryExceptionError, hope to hear from you! Cheers. – Eduardo Dec 29 '20 at 23:06
  • 4
    I have Laravel 8.x and no config/fortify.php class. Nor that array. – Laynier Piedra May 07 '21 at 14:21
  • 1
    @LaynierPiedra You have to publish it. Presumably you did this to create the Fortify service provider and migration, no? https://laravel.com/docs/8.x/fortify#installation `php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"` `Copied File [/vendor/laravel/fortify/stubs/fortify.php] To [/config/fortify.php]` `Copied File [/vendor/laravel/fortify/stubs/FortifyServiceProvider.php] To [/app/Providers/FortifyServiceProvider.php]` `Copied Directory [/vendor/laravel/fortify/database/migrations] To [/database/migrations]` `Publishing complete.` – Joel Mellon Nov 06 '21 at 18:59
  • I did not installed Fortify – Laynier Piedra Nov 12 '21 at 15:14
  • how to disable logout feature? – habib Sep 04 '22 at 15:09
  • 1
    This is the correct way to use Laravel. – Nighon May 04 '23 at 01:23
12

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.

cakan
  • 2,099
  • 5
  • 32
  • 42
7

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.

2

Remove the registration routes from config/auth.php and then create a config/fortify.php (paste the content from: vendor/laravel/fortify/config/fortify.php) which will override the default settings.

Inside config/fortify.php comment out the first element of features array (Features::registration()) then run php artisan optimize to clear config cache and routes cache.

Now all your removed routes should return 404, you can also check if those still exist with php artisan route:list

config/fortify.php:

<?php

use Laravel\Fortify\Features;

return [
    'guard' => 'web',
    'middleware' => ['web'],
    'passwords' => 'users',
    'username' => 'email',
    'email' => 'email',
    'views' => true,
    'home' => '/home',
    'prefix' => '',
    'domain' => null,
    'limiters' => [
        'login' => null,
    ],
    'features' => [
        //Features::registration(),
        Features::resetPasswords(),
        Features::emailVerification(),
        Features::updateProfileInformation(),
        Features::updatePasswords(),
        Features::twoFactorAuthentication(),
    ],
];
Adrian P.
  • 176
  • 2
  • 6
2

Just use:

Auth::routes(['register' => false]);
Bauroziq
  • 951
  • 9
  • 14
1

Do not break your head with different versions of packages and Laravel. Because maybe you don't have fortify.php in your config, or using different packages. All routes are in routes/web now. Just go there and force that '/register' sends to login or any other view you want to:

Route::any('/register', function() {
    return  view('auth.login');
});

That way you maintain out of reach that feature, but close for when you need it.

Laynier Piedra
  • 425
  • 6
  • 16
0
Auth::routes(['register' => false]);

If the changes still don't reflect, clear the route:cache by doing as below:

PHP artisan ro:cache
hackernewbie
  • 1,606
  • 20
  • 13
-1

Remove this code from routes/auth.php

Route::get('/register', [RegisteredUserController::class, 'create'])
                ->middleware('guest')
                ->name('register');

Route::post('/register', [RegisteredUserController::class, 'store'])
                ->middleware('guest');
-1

Just put this in your /routes/web.php:

Route::any('/register', [App\Http\Controllers\HomeController::class, 'index']);
bad_coder
  • 11,289
  • 20
  • 44
  • 72