laravel 5.3 disable registration

David Carr

Laravel Framework

Laravel comes with built in authentication to enable it first create the users table by running the default migrations:

php artisan migrate

Next create the authentication:

php artisan make:auth

Once run auth views and controllers will be created and the default layout file will have a login and register link.

You may not want the register part, removing the link from the template is not enough the routes and view/controller still exist. The can be deleted but a better way is to just disable the loading of the register view.

To do this open app/http/Controllers/Auth/RegisterController.php, this classes uses a RegistersUsers trait which contains a protected method to load the view. That’s in the core but you should never touch the core so instead overwrite that method by creating a method with the same name in RegisterController.php and instead of loading a view redirect to the home page or anywhere you like:

public function showRegistrationForm()
{
    return redirect('/');
}

While you’re at it disable the create method too:

protected function create(array $data)
{
    return redirect('/');
    /*return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);*/
}

This will stop the view from loading and stop the create from running. But if you change your mind later you can revert these back easily.

Do you know of a better way? let me know in the comments below.

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.