Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable registration new users in Laravel

Tags:

php

laravel

I'm using Laravel. I want to disable registration for new users but I need the login to work.

How can I disable registration form/routes/controllers?

like image 291
Milad Rahimi Avatar asked Oct 08 '22 13:10

Milad Rahimi


People also ask

How to disable registration 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 disable registration in jetstream?

To disable registration go to config/fortify. php and comment out Features::registration().


Video Answer


2 Answers

Laravel 5.7 introduced the following functionality:

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

The currently possible options here are:

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.4
  • Auth/RegisterController.php for Laravel 5.5
public function showRegistrationForm()
{
    return redirect('login');
}

public function register()
{

}
like image 98
Limon Monte Avatar answered Oct 13 '22 10:10

Limon Monte


This might be new in 5.7, but there is now an options array to the auth method. Simply changing

Auth::routes();

to

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

in your routes file after running php artisan make:auth will disable user registration.

like image 39
theeternalsw0rd Avatar answered Oct 13 '22 08:10

theeternalsw0rd