How do I restrict access to the user registration page?

1

Next I am creating a project in laravel 5.2 I used the auth classes of laravel itself.

And I would like to know how I can be setting it up so that the /register page is accessed only after the user logs in. Because by default it comes without validation and anyone can access it.

My route.php looks like this:

Route::group(['middleware' => ['web']], function () {
//
    Route::get('/', 'Auth\AuthController@getLogin');
});


Route::group(['middleware' => 'web'], function () {
  Route::auth();
  Route::get('/home', 'HomeController@index');
  //Route::get('/register', 'Auth\AuthController@getRegister');
});
    
asked by anonymous 19.03.2016 / 17:12

1 answer

1

Just change the authentication controller middlewares to:

/**
 * Create a new authentication controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest', ['except' => ['logout', 'register', 'showRegistrationForm']]);
    $this->middleware('auth', ['only' => ['register', 'showRegistrationForm']]);
}

I added the methods register and showRegistrationForm in the middleware auth and removed from guest , otherwise the user would be redirected to the home if he was logged in.

    
20.03.2016 / 02:07