Okay, so i have been playing around with it, and i still don't get the result. Thank you very much for the already suggested solutions!
It's a little difficult to explain it, without adding a picture, but i'll try anyways.
So, right now what i have is, lets say that there is a booking from 10:00 - 12:00 - all the time slots says "booked", so:
08:00 - free
09:00 - free
10:00 - booked <---- This one should have a modal instead of the text booked.
11:00 - booked
12:00 - free
13:00 - free\
What i achieved by adding $loop->first, is, if we say i have a booking again from 10:00 - 12:00, the i get this:
08:00 - free
09:00 - free
10:00 - modal
11:00 - booked
12:00 - free
13:00 - free
But if there is a booking, lets say from 16:00 - 18:00
14:00 - free
15:00 - free
16:00 - booked <---- We are back at booked, because it only check the first one.
17:00 - booked
18:00 - free
19:00 - free
I think the problem might be my function here:
@if($bookings->some(fn($booking) => $booking->isHourBooked($hour->hour)))
This is the isHourBooked function:
public function isHourBooked(Carbon $hour)
{
return $this->start_time->lessThanOrEqualTo($hour) && $this->end_time->greaterThanOrEqualTo($hour);
}
So, as we can see, this will return a boolean.
I have tried to include the start_time with this function:
public function isHourStartOfBooking(Carbon $hour)
{
return $this->start_time->eq($hour);
}
And did this in the view:
@if($bookings->some(fn($booking) => $booking->isHourBooked($hour->hour)))
booked
@if($bookings->some(fn($booking) => $booking->isHourStartOfBooking($hour->hour)))
<p>Hi </p>
@endif
@endif
But still no luck.
Edit: I really tried to add some linebreaks (with \ and \n), but i simply can't get it to work.