How to Disable Laravel User Registration

In laravel on 2~4 minutes
How to Disable Laravel User Registration

If you do not limit the access to your Laravel 8 web application using user roles, permission or similar technique, any visitor will be able to register for an account and access the entire application without any restriction. For that kind of application, we should consider limiting the access by disabling the user registration feature.

When we create a fresh Laravel 8 application, it does not have any user authentication mechanism. As mentioned in the official documentation, we should manually implement it by ourselves or use a Laravel Starter Kit like Laravel Breeze, Laravel Jetstream or Laravel UI. Let’s see how to disable user registration with these Starter Kits.

Disable User Registration In Laravel Breeze

There is no straightforward method to disable user registrations in Laravel Breeze, however, we can comment out or completely remove the get and post user registration routes in /routes/auth.php file.

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

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

Once we removed these registration routes, the “Register” link on the home page (welcome.blade.php) will be automatically removed as it checks whether registration routes are available or not. However, still, people who directly visit the /register URL will see a 404 page. We can leave it as it is or even we can redirect these requests to the /login page by adding the following code to the /routes/web.php file.

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

Disable User Registration In Laravel Jetstream

Under the hood, Laravel Jetstream uses the front-end agnostic authentication backend, Laravel Fortify. So, all we need to disable user registrations in Laravel Jetstream is, open the /config/fortify.php file and scroll down to the bottom. In the end, there will be an array called “features”. In that array, remove or comment out the Features::registration(), line like below.

'features' => [
    // Features::registration(),
    Features::resetPasswords(),
    // Features::emailVerification(),
    Features::updateProfileInformation(),
    Features::updatePasswords(),
    Features::twoFactorAuthentication([
        'confirmPassword' => true,
    ]),
],

Disable User Registration In Laravel UI

Open the /routes/web.php file. It should have a line similar to the following.

Auth::routes();

Pass the ['register' => false] array as an argument the routes() method like below.

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