I have two models, User and School; they both return belongs to many of each of them.
I'm trying to return a list of Users that has the same School as the user logged in.
USER MODEL
public function school(){
return $this->belongsToMany(School::class, 'school_user');
}
SCHOOL MODEL
public function user(){
return $this->belongsToMany(User::class, 'school_user');
}
The Eloquent Query
$students = User::role('Student')->with('school')->where('school_id', auth()->user()->school->id)->latest()->paginate(25);