Laravel: Disable “Booked” times from time range

孤街醉人 提交于 2019-12-11 19:37:33

问题


I'm trying to disable a box within a range of times throughout the day.

The day starts with an Employee's set day/time range, so for example, if the employee works on a Tuesday, 9-5 and a service which is 1 hour long, their last booking is 4pm as that is the last working hour slot for a booking. This logic works fine, however it's inserting the 'booked' slots within the day that I'm struggling with.

@php
$employee_booking = $bookings->where('employee_id',$employeedetails->id)->where('start_date', date('Y-m-d', strtotime($_GET['booking_date'])))->all();
@endphp

@for ($i=$start_time;$i<=$end_time;$i = $i + 30*60)
    @foreach($employee_booking as $booking)
        @if($i >= strtotime($booking->start_time) && $i <= strtotime($booking->end_time))
            Booking [unavailable] {{ $booking->start_time }} - {{ $booking->end_time }} ({{$booking->title}}) <br>
        @else
            {{ date('H:i a', $i) }} [available] <br>
        @endif
    @endforeach
@endfor

In the example above, it's based on the employee's working hours pulling from the database specified as: 8am - 4pm. Please see this screenshot (list very long to add to thread): http://prntscr.com/k9e9b2

As you can see from the outputted data, they are repeating the times because it's in a foreach loop but I'm not sure of any other way to get this data to work.

The purpose of this data is to be fashioned into something more presentable, like so: http://prntscr.com/k9e9pp - As you can see from this example, the booking that's unavailable has been blocked out, this needs to be repeated to all other bookings for that day, not just the one for that example.

I'm assuming it has to go into an array and then somehow pulled through but it's this step that I'm really struggling with.

I hope this is enough information for someone to help me out.

Thanks in advance!

Matt

来源:https://stackoverflow.com/questions/51461134/laravel-disable-booked-times-from-time-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!