m.donicova's avatar

Disable registration in built-in registration Laravel 5.3

I use built-in authentication in laravel 5.3 , but I want disable user registration. What is the best solution for this?

0 likes
11 replies
m.donicova's avatar

Laravel version 5.3.9 have not AuthController

m.donicova's avatar

Method App\Http\Controllers\Auth\RegisterController::showRegistrationForm() does not exist

m.donicova's avatar

I disable Auth::routes()

and added

// Login Routes...
    Route::get('login', ['as' => 'login', 'uses' => 'Auth\LoginController@showLoginForm']);
    Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\LoginController@login']);
    Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\LoginController@logout']);

// Registration Routes...
//    Route::get('register', ['as' => 'register', 'uses' => 'Auth\RegisterController@showRegistrationForm']);
//    Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\RegisterController@register']);

// Password Reset Routes...
    Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\ForgotPasswordController@showLinkRequestForm']);
    Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\ForgotPasswordController@sendResetLinkEmail']);
    Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\ResetPasswordController@showResetForm']);
    Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\ResetPasswordController@reset']);
});
1 like
sherwinmdev's avatar

@m.donicova in your Auth\RegisterController.php file override the showRegistrationForm() with the following code.

protected function showRegistrationForm()
    {
        return redirect()->to('login')->with('warning', 'Registration is disabled.');
    }

now when the url /register is envoked it will redirect to the login page and display a warning message. of course, you can redirect it to where ever you want and change the message to whatever you want. this should work on 5.3 and 5.4.

5 likes
erellsworth's avatar

I did this by changing the constructor in Auth\RegisterController.php From:

    public function __construct()
    {
        $this->middleware('guest');
    }

to:

    public function __construct()
    {
        $this->middleware('auth');
    }

This way you can create new users if you want, but you have to be logged in first.

14 likes

Please or to participate in this conversation.