Laravel 5.4 blade foreach loop
I don't know how your data looks, but by looking at your code columns availble_times
and booking_time
are date fields. If Times model is dictionary for hours (like 1. 8.00, 2. 8:45, 3. 9:00) , and booking hour has to be in Times records, then you just need to invert the loops to display each time for each booking
@foreach($bookings as $booking) @foreach($times as $time) <tr> <td>{{ getImaginedChairNumber() }}</td> <td>{{ $time->availble_times }}</td> @if($time->availble_times == $booking->booking_time) {{-- There is already booking for that dictionary time --}} <td>not available</td> @else <td>available</td> @endif </tr> @endforeach@endforeach
Should produce similar table:
╔═══════╦══════╦═══════════════╗║ Chair ║ Time ║ Booking ║╠═══════╬══════╬═══════════════╣║ A1 ║ 8:00 ║ not available ║║ A1 ║ 8:45 ║ available ║║ A1 ║ 9:00 ║ not available ║║ A2 ║ 8:00 ║ not available ║║ A2 ║ 8:45 ║ not available ║║ A2 ║ 9:00 ║ not available ║║ A3 ║ 8:00 ║ available ║║ A3 ║ 8:45 ║ available ║║ A3 ║ 9:00 ║ not available ║╚═══════╩══════╩═══════════════╝
Is this the correct form of the output table you expect?(I used this tool to draw ascii table https://senseful.github.io/web-tools/text-table/)