0

I need to give admin access to all methods in controller, but only to some for customer-admin.

I tried to go with this

public function __construct()
{
    $this->middleware('auth');
    $this->middleware('role:customer-admin')->only(['show', 'edit', 'update', 'upload_picture']); // should give access to select methods
    $this->middleware('role:admin'); // should give access to all methods
}

But it seems that in this case you have to conform to both.

Edmund Sulzanok
  • 1,883
  • 3
  • 20
  • 39

1 Answers1

0

As counterintitive it may seem, here you have to combine roles based on methods. So the right answer would be:

public function __construct()
{
    $this->middleware('auth');
    $this->middleware('role:customer-admin|admin')->only(['show', 'edit', 'update', 'upload_picture']);
    $this->middleware('role:admin')->only(['index', 'create', 'store', 'destroy]); //Indicate methods that are exlusive to admin
}
Edmund Sulzanok
  • 1,883
  • 3
  • 20
  • 39