I have this collection by query below and I want to group all elements by curriculum_id like this
public function getByClassroomId($classroomId)
{
$marks = ClassroomMarkBook::with([
'classroomSubject' => function ($query) use ($classroomId) {
$query->where('classroom_id', $classroomId);
},
'classroomSubject.subject'
])->get();
$result = [];
foreach ($marks as $mark) {
if(!is_null($mark->classroomSubject)){
$result[$mark->student_id][$mark->classroomSubject->id][] = $mark;
}
}
return $result;
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2SvNeIL
via IFTTT
Aucun commentaire:
Enregistrer un commentaire