for my school project i had a laravel project delivered. but my controller has a fatal error in it. if(Auth::user()->hasRole('admin')){...} "
but the hasRole gives a error: undefined method 'hasRole'
CodePudding user response:
It's because there is no default hasRole function in laravel for User model. In order to do that you must define it yourself in User.php or define a trait that has a hasRole function and then use it in User model.
CodePudding user response:
add this in User model
public function hasRole($role)
{
return User::where('role', $role)->get();
}
