写多对多关系的时候又发现问题
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
foreach($this->getPermissions() as $permission){
$gate->define($permission->name, function($user) use ($permission){
return $user->hasRole($permission->roles);
});
}
}
User里
public function hasRole($role)
{
if(is_string($role)){
return $this->roles->contains('name',$role);
}
return !! $role->intersect($this->roles)->count();
}
然后提示有错误
FatalErrorException in User.php line 60: Call to a member function intersect() on a non-object
请各位高手指导一下