class Appointment extends Model
{
public function counselor()
{
return $this->belongsTo(User::class, 'counselor_id');
}
public function student()
{
return $this->belongsTo(Student::class);
}
}
controller
$user = Auth::user();
$appointments = Appointment::query()
->with(['student']) // eager load appointment's student
->where('counselor_id', $user->id) // filter by current user
->whereHas('student') // only appointments with students
->get();
return view('appointedStudents')->with('appointments', $appointments);
I can get student details
but i want to get counselor details too