I got Users, Absences and Reasons tables:
Users
id | name
Absences
id | user_id:foreignKey | reason_id:foreignKey | deputy_id:foreignKey | start:date | end:date
Reasons
id | name
I got attendance calendar which looks like:
Day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
-----------------------------------------------|
User1 | o | o | V | V | S | S | o | o | o | V |
-----------------------------------------------|
User2 | T | o | o | o | H | V | o | V | o | V |
-----------------------------------------------|
Where “V” is Vacation, “S” sick etc. I want to print each User attendance report in that table.
@foreach ($users as $user )
<tr>
<td> {{ $user->name }} </td>
@if($user->absences != null)
@foreach($days as $day)
@foreach ($user->absences as $absence)
@if($day >= $absence->start->format('d') && $day <= $absence->end->format('d'))
// there check if $user->absence->reason_id == something ...
@else
@endif
@endforeach
@endforeach
@endif
</tr>
@endforeach
Also I want to have a tooltip, where I print specific data for each day (reason name, deputy name).
I have no idea how to get the range between two dates in each absence, merge it to got f.e table of user absence days with another array with reason.:
[
2 => ['reason_id => 1, deputy_id = 3],
3 => ['reason_id => 1, deputy_id = 3],
7 => ['reason_id => 2, deputy_id = 1]
]
Where keys [2,3,7] are the days of the absence.
Is there easier way to achieve that or should I rebuild the database structure?