I have a one-to-many relationship between group and students and I want to get all students of some groups so I do this:
public function getStudentsOfGroups()
{
$groups = Auth::user()->groups;
foreach($groups as $group){
$students = $group->students;
}
return view('teacher.home', compact('students'));
}
but it doesn't get the data I need, so what can I do instead?
$students[] = $group->students;
otherwise you will only see the data from the last iteration