In blade you are using $booking where in the controller you have declared the variable $booking"s". May be that could be the solution.
Laravel blade doesn't render all from foreach
Hi, I have a Booking and Service table and a pivot table to connect them. I'm trying to get the services for these bookings but it always renders the else statement:
@if (!$booking->services->isEmpty())
<div class="flex my-4">
<div class="w-64 self-center">
<h3 class="font-light text-xl">Þjónusta:</h3>
</div>
<div class="flex-1 text-right">
<ul>
@foreach ($booking->services as $service)
<li>
<p class="font-bold">{{ $service->description }}</p>
</li>
@endforeach
</ul>
</div>
</div>
@else
<div class="flex my-4">
<h3 class="font-light text-xl italic">Ekki var valið þjónusta</h3>
</div>
@endif
I have a booking inside my database (id: 14) and then I have a row in booking_service (14, 3) and then I have a service in my database (id: 3). And I'm trying to get the description of the service.
It was working before, then I changed from this:
$bookings = Booking::where('dropOffDate', $today)->orderBy('flightTime', 'asc')->get();
to this:
$bookings = Booking::where('dropOffDate', $today)
->orWhere('pickUpDate', $today)
->orderBy('flightTime', 'asc')
->get();
He said to eager load the services relationship.
$bookings = Booking::with('services')->where(....)
Please or to participate in this conversation.