【问题标题】:Zizaco/Entrust multiple method filtersZizaco/Entrust 多方法过滤器
【发布时间】:2019-03-26 12:12:44
【问题描述】:

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

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

【问题讨论】:

    标签: laravel-5 entrust


    【解决方案1】:

    这似乎违反直觉,在这里您必须根据方法组合角色。所以正确的答案是:

    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
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 2016-12-04
      • 2018-02-12
      • 2016-07-28
      • 2014-05-05
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多