How to restrict access to user registration page?

Asked

Viewed 779 times

1

Following people I am creating a project in Aravel 5.2 I used the auth classes of the Aravel itself.

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

My route.php is as follows:

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');
});

1 answer

1


Simply 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 middleware auth and removed from guest, otherwise the user would be redirected to the home if he were logged in.

  • It was cool but I came up with another question, when I log in it always directs to Register how do I redirect to /Dashboard for example and only access Register if I call.

  • @This is already a different question. Different questions need to be dealt with on different topics. Take a [tour] to better understand how OS-PT works.

  • Okay thanks I’ll give a search.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.