I need to do a grouping by date. The problem that are two tables "kanban" and "apontamentos".
something like: Kanban::with('apontamentos')->get()->groupBy('dataApontamento'); property error
I've tried everything, use "groupBy" in the model. Need to know how to group in the controller and do the "foreach"
closest I ever got was that way:
$days = Kanban::with('apontamentos')->get()->groupBy(function ($val) {
return $val->dataApontamento;
});
// dd($days);
foreach ($days as $day => $appointments) {
echo '<h2>'.$day.'</h2><ul>';
foreach ($appointments as $appointment) {
echo '<li>'.$appointment->atividade.'</li>';
}
echo '</ul><br>';
}
clearer example:
Kanban
Title: waiting for service
Apontamentos
date 05/05
Project1
Project2
Project3
date 06/05
Project1
Project2
Project6
Project7
Kanban
Title: pending
apontamentos
date: 08/05
Project9
Project8
Project4
Kanban
Title: Kanban
Title: waiting for service
apontamentos
date: 09/05
Project1
Project1
Project1
Project1
10/05
Project1
Project1
Project1
Project1