Authentication in Laravel

0

Using Laravel, what can I do so that only authenticated users can register for new users? As a result, the user registration page would only be accessed by authenticated users. In the default settings of Laravel the registry is done freely.

    
asked by anonymous 30.08.2016 / 21:58

1 answer

1

I'll assume you're using the 5.3 version of Laravel. The simplest way is to assign the Auth middleware in the constructor of your \App\Http\Controllers\Auth\RegisterController class, like this:

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth'); // anteriormente definida como guest.
}

If you check your route list with the command php artisan route:list , you will see that from now on the log routes (the last two of the following image) are protected by the authenticated user middleware (auth).

Figure1:Authauthenticatedusermiddlewareregistrypaths

IfyouareusingapreviousversionofLaravel,becausethisisaverylow-levelquestion,youcanchecktheofficialdocumentationpage.Forexample,inthe controllers page of version 5.2, there is a specific topic for assigning multiple middleware in the routes and in the constructor of a controller.

    
31.08.2016 / 13:06