Zizaco /委托多方法过滤器

时间:2018-10-22 12:09:35

标签: laravel-5 entrust

我需要授予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
}

但是,在这种情况下,您似乎必须同时遵守两者。

1 个答案:

答案 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
}