May 9, 2016
0
Level 5
filtering relationships
I need to get a collection of all the students in all the sessions in all timeslot on each day...
Student model:
public function sessions()
{
return $this->belongsToMany('App\Session')->withTimestamps();
}
Session model:
public function students()
{
return $this->belongsToMany('App\Student')->withTimestamps();
}
public function timeslot()
{
return $this->belongsTo('App\Timeslot');
}
Timeslot model
public function sessions()
{
return $this->hasMany('App\Session');
}
Timeslot table has columns "day" and "slot".
If i wanted to get a large collection containing the days => slots =>sessions => students should i just iterate over days then timeslots then sessions and students and try to add to a collection or is there a better way (I hope so)...
Please or to participate in this conversation.