Disable register in Laravel

Laravel 5.2+ give us a way to scaffold all of the routes, controllers and views we need for authentication with one command:

php artisan make:auth

This command gives us 3 controllers (HomeController, AuthController and PasswordController) with some methods and the routes showed below, with the command:

php artisan route:list

php-artisan-route-list

If we want to disable the register, we have to disable the «showRegistrationForm» and the «register» methods in the «AuthController», placed in the «app\Http\Controllers\Auth» folder.

This controller uses the «AuthenticatesAndRegistersUsers» trait, which uses the «RegistersUsers» trait.

We only have to overwrite this two methods in this controller (AuthController)

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

public function register()
{
}

In the first method «showRegistrationForm()» we redirect the request to the login page and in the second method «register()» we do nothing.

We can delete the view «resources/views/auth/register.blade.php» because we won’t use it and we have it in the Git (or in another version control system) if we will need it.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.