我在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;
});
}
答案 0 :(得分:1)
问题已解决!
public function boot()
{
$this->registerPolicies();
Gate::define('isAdmin', function ($user) {
return $user->role == 1;
});
}