Problem
I’m working with Laravel. I’d like to disable new user registration, but I need the login to function.
How can I turn off the registration form, routes, and controllers?
Asked by Milad Rahimi
Solution #1
The following features were added to Laravel 5.7:
Auth::routes(['register' => false]);
The following are the currently available options:
Auth::routes([
'register' => false, // Registration Routes...
'reset' => false, // Password Reset Routes...
'verify' => false, // Email Verification Routes...
]);
Simply override the showRegistrationForm() and register() functions in older Laravel versions.
public function showRegistrationForm()
{
return redirect('login');
}
public function register()
{
}
Answered by Limon Monte
Solution #2
This may be new in 5.7, however the auth method now has an options array. Simply altering
Auth::routes();
to
Auth::routes(['register' => false]);
After running php artisan make:auth in your routes file, user registration will be disabled.
Answered by theeternalsw0rd
Solution #3
If you’re using Laravel 5.2 and installed the auth-related functionality with php artisan make:auth, then invoking Route::auth in your app/Http/routes.php file will include all auth-related routes ().
In vendor/laravel/framework/src/Illuminate/Routing/Router.php, you’ll find the auth() method. So, if you want to disable registration by eliminating undesirable routes, as some people propose (which is probably a good idea), copy the routes you still want from the auth() method and put them in app/Http/routes.php (replacing the call to Route::auth()). As an example:
<?php
// This is app/Http/routes.php
// Authentication Routes...
Route::get('login', 'Auth\AuthController@showLoginForm');
Route::post('login', 'Auth\AuthController@login');
Route::get('logout', 'Auth\AuthController@logout');
// Registration Routes... removed!
// Password Reset Routes...
Route::get('password/reset/{token?}', 'Auth\PasswordController@showResetForm');
Route::post('password/email', 'Auth\PasswordController@sendResetLinkEmail');
Route::post('password/reset', 'Auth\PasswordController@reset');
It’s definitely different if you’re running a version lower than 5.2; I recall things changing quite a bit since 5.0, and artisan make:auth was even deleted at one point, IIRC.
Answered by RafaĆ G.
Solution #4
Here’s how to do it right with Laravel 5.3 and 5.4:
You must make the following adjustments:
public function __construct()
{
$this->middleware('guest');
}
to
public function __construct()
{
$this->middleware('auth');
}
in app/Http/Controller/Auth/RegisterController.php
Answered by Yassin
Solution #5
You can now send an array of options to Auth::routes in Laravel 5.7. (). The registration routes can then be disabled with the command:
Auth::routes(['register' => false]);
The source code for this can be found in src/Illuminate/Routing/Router.php.
Answered by Christopher Geary
Post is based on https://stackoverflow.com/questions/29183348/how-to-disable-registration-new-users-in-laravel