Disable Laravel Registration Routes Example: In thi tutorial you will learn How to disable registration new users in Laravel. You can use this example to disable register route in laravel 5 below, laravel 6, laravel 7, laravel 8 or laravel 9 application.
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.
Example 1: In Laravel 6 < Below Apps
Here in the web.php file we have default auth routes where we pass array as argument and pass ‘register’ false so they will disabled register route in laravel app.
routes/web.php
Auth::routes(['register' => false]);
The currently possible options which we can disable:
Auth::routes([
'register' => false, // Registration Routes...
'reset' => false, // Password Reset Routes...
'verify' => false, // Email Verification Routes...
]);
For older Laravel versions just override showRegistrationForm()
and register()
methods in
AuthController
for Laravel 5.0 – 5.4Auth/RegisterController.php
for Laravel 5.5
public function showRegistrationForm()
{
return redirect('login');
}
public function register()
{
}
Example 2: In Laravel 6+ Apps
Laravel 6+ version apps 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(),
],
I hope these example works for you.