代码之家  ›  专栏  ›  技术社区  ›  Edmund Sulzanok

Zizaco/委托多方法过滤器

  •  0
  • Edmund Sulzanok  · 技术社区  · 6 年前

    我需要给予 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 回复  |  直到 6 年前
        1
  •  0
  •   Edmund Sulzanok    6 年前

    正如反义词看起来的那样,这里您必须根据方法组合角色。所以正确的答案是:

    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
    }