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

时间:2018-09-28 15:37:47

标签: php laravel laravel-5 laravel-5.6

我在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;
        });
}

1 个答案:

答案 0 :(得分:1)

问题已解决!

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

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