Laravel 5.4 blade foreach loop

后端 未结 1 1016
滥情空心
滥情空心 2021-01-11 19:27

I am building a venue manangement system, and on the landing page, i m trying to show all the available slots to the visitors. The ones that have already been booked are sho

1条回答
  •  借酒劲吻你
    2021-01-11 20:06

    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)
            
                {{ getImaginedChairNumber() }}
                {{ $time->availble_times }}
                @if($time->availble_times == $booking->booking_time)
                    {{-- There is already booking for that dictionary time --}}
                    not available
                @else
                    available
                @endif
            
        @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/)

    0 讨论(0)
提交回复
热议问题