I have the User and Regional models, which I want to get some regionals from the user type of supervisor. So here is how I define the relationship.
public function regional()
{
return $this->belongsTo(Regional::class);
}
/**
* Get all user that belongs to this supervisor
*
* @return mixed
*/
public function amOfSupervisor()
{
return $this->hasMany(User::class, 'supervisor_id');
}
I can get the user's regional by $user->regional
, but how to get all regional based on the user that belongs to this user? I've tried hasManyThrough()
but always an error. What's wrong, or what should I do?
public function RegionalSV()
{
return $this->hasManyThrough(Regional::class,
User::class,'supervisor_id', 'regional_id');
}