从模型授权


小鬼
2025-03-17 01:31:12 (1天前)


确定

授权
</跨度>
为用户。

在刀片中,@ can(‘view’,$ board)有效
在控制器中,$ this-&gt; authorize(‘view’,$ board)有效

但我不能为我的生活找到任何方式来称呼政策

授权
</跨度>
来自董事会模式

我尝试过的:

Gate :: check(‘view’,$ this)//非静态方法,没问题,但没想到它会起作用
auth() - &gt; user() - &gt; can(‘view’,$ this)//这甚至不是

2 条回复
  1. 0# 真不错 | 2019-08-31 10-32



    事实证明这是

    Laratrust

    包使用的

    can()

    特征中的方法,所以我无法将自己的可授权特征添加到我的用户模型中



    固定:




    1. use LaratrustUserTrait;
      use Authorizable {
      LaratrustUserTrait::can insteadof Authorizable;
      Authorizable::can as authorize;
      }

    2. </code>

登录 后才能参与评论