isuru's avatar
Level 1

How to disable User Registration in Laravel 5.7

Is there a way to disable User Registration in Laravel without editing vendor files?

0 likes
8 replies
frankperez87's avatar

You could bring in the routes that you want to use specifically into your routes/web.php instead of using the Auth::routes() method.

If the route is not defined, the access will not be available for any user.

Here are the list of routes that belong to a user Authenticating, Registering, Resetting Passwords, and Email Verfication.

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

// Registration Routes...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');

// Password Reset Routes...
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');

// Email Verification Routes...
$this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
$this->get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
$this->get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');

You can find all of these routes defined within the /vendor/laravel/framework/src/Illuminate/Routing/Router.php file under the public auth method.

Keep in mind that Auth::routes() is just a convenient helper for generating the above list of routes, but not necessary.

2 likes
Cruorzy's avatar

If you ever ran the php artisan make:auth command then I would personally do the same thing in a new repo with git setup, see exactly which files are modfied and created and roll that back in the project where you want to disable it.

If you never ran the command then it is not enabled.

fbss's avatar

I don't know if this is good solution, but you can return 404 in register controller so if any users visits register page 404 page will be shown

sineir's avatar

hi... in web.php (routes) use: Auth::routes(['register'=>false]);

parameteres acepted: 'register' and 'verify' // automatize for email !!!! public function auth(array $options = []) ........if ($options['register'] ?? true) { .........if ($options['verify'] ?? false) {

5 likes
Edgeset's avatar

in routes/web.php

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

It will throw a 404 in /register

26 likes
braed's avatar

@EDGESET - This is the Laravel way and should be the accepted answer, thank you.

Please or to participate in this conversation.