0

我需要授予admin对控制器中所有方法的访问权限,但仅限于一些 for 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
}

但似乎在这种情况下你必须同时符合两者。

4

1 回答 1

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
}
于 2018-10-29T06:42:48.480 回答