I'm trying to make a time management schedule. The table is like this:
Days | Start | End
Monday | 08:00 | 11:00
Tuesday | 07:00 | 12:00
...
I want to keep showing days from Monday to Sunday even though in database there's no data for it.
I want the result to be like this:
Days | Start | End |
Monday | 08:00 | 11:00 |
Tuesday | 07:00 | 12:00 |
...
Sunday | - | - | // if there's no sunday data in database it still
// showing sunday but the start & end is empty
There's also a chance where the results of query is null, so it will end up error because I don't have any value inside variable when using foreach later in views.
This is my controller:
$work_hours = AttendanceGroupWorkHour::where('attendance_group_id', $id)->get();
And this is my view:
@foreach ($work_hours as $work_hour)
<tr>
<td>
{{ $work_hour->days)
</td>
<td>
{{ $work_hour->start)
</td>
<td>
{{ $work_hour->end)
</td>
</tr>
</tbody>
@endforeach
Sorry but I really don't have any idea how to do it. Any help would be helpful for me.