【问题标题】:Call to undefined method Illuminate\Support\Facades\Gate::define()调用未定义的方法 Illuminate\Support\Facades\Gate::define()
【发布时间】:2019-03-04 15:30:36
【问题描述】:

我在 Laravel 5.6 中使用 Policy

但是得到这个错误:

调用未定义的方法 Illuminate\Support\Facades\Gate::define()

我该如何解决这个问题?

protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

并在启动时:

public function boot(GateContract $gate)
{
        $this->registerPolicies();

        $gate->define('isAdmin', function ($user){
            return $user->role == 1;
        });
}

【问题讨论】:

  • 如果将$gate->define 替换为Gate::define 会发生什么?

标签: php laravel laravel-5 laravel-5.6


【解决方案1】:

问题解决了!

public function boot()
{
    $this->registerPolicies();

    Gate::define('isAdmin', function ($user) {
        return $user->role == 1;
    });
}

【讨论】:

  • 你能解释一下是什么问题吗?
  • 我没有添加 Gate 类。
猜你喜欢
  • 2019-10-15
  • 2020-01-24
  • 2023-03-24
  • 2019-05-14
  • 2021-10-29
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多