Have you see some of these: https://laracasts.com/discuss?q=group+by+date
And looked at group by here
https://laravel.com/docs/5.5/queries#ordering-grouping-limit-and-offset
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, this might seem like a beginner question, but I have been trying at this for days with no luck.
I have an attendance model linked using eloquent with User model as shown here
public function users()
{
return $this->BelongsToMany(User::class);
}
public function attendances()
{
return $this->BelongsToMany(Attendance::class);
}
The controller method index
public function index()
{
$attendances =Attendance::all();
dd($attendances);
$date = Carbon::now();
$date = $date->toDateString();
$present = Attendance::where('status' , 'Present')->where('date' , $date)->get();
$absent = Attendance::where('status' , 'Absent')->where('date' , $date)->get();
return view('attendance.index',compact('attendances','present','absent','date'));
}
I want in the view to display the total number of users present for the day the attendance is taken, currently the only way I managed to do is getting it to work through comparing today's date with the absent - present, which is wrong. so to further display here is the view
@foreach($attendances as $attendance)
<tr role="row" class="odd">
<td class="sorting_1">{{count($present)}} Present</td>
<td class="sorting_1">{{count($absent)}} Absent</td>
<td>{{$attendance->date}}</td>
<td>
<a class="btn btn-square btn-info" href="#" role="button">View</a>
<a class="btn btn-square btn-warning" href="#" role="button">Edit</a>
</td>
</tr>
@endforeach
Hope I didn't over confuse my question..
Please or to participate in this conversation.