我需要授予admin
访问控制器中所有方法的权限,但仅授予customer-admin
中某些方法的访问权限。
我尝试与此
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
}
但是,在这种情况下,您似乎必须同时遵守两者。
答案 0 :(得分:0)
看起来似乎是对立的,在这里您必须根据方法组合角色。因此正确的答案是:
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
}