0

I need to grant the ability of new user creation to admin only. Intuitively, I've tried to restrict access to the getRegister and postRegister actions (which are located in AuthenticatesAndRegistersUsers trait used in AuthController) using Entrust middleware in the AuthController, but this doesn't seem to have any effect whatsoever - the registration page is still accessible by guest users. Here is the corresponding code:

// AuthController
public function __construct()
{
    $this->middleware($this->guestMiddleware(), ['except' => 'logout']);

    // CUSTOM MODIFICATIONS
    $this->middleware('role:admin', ['only' => ['getRegister', 'postRegister']]);
}

What am I doing wrong?

Alex Lomia
  • 6,705
  • 12
  • 53
  • 87

1 Answers1

0

You need to add middleware in your route like this.

Route::get('register', ['middleware' => 'role:admin','as' => 'register', 'uses' => 'LoginController@getRegister']);
Alex Lomia
  • 6,705
  • 12
  • 53
  • 87