Laravel Framework

laravel 5.3 disable registration

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.

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.