Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hjortur17's avatar

Property [description] does not exist on this collection instance.

Hi, I can't figure out why I'm getting this error message when I'm trying to load the service description from the booking. This is the error message I get: Property [description] does not exist on this collection instance.

BOOKING MODEL

public function services()
{
	return $this->belongsToMany('App\Service');
}

FOREACH LOOP

@foreach ($bookingsGoingOut as $booking)
	<tr>
		<td class="border px-4 py-2">{{ optional($booking->services)->description }}</td>
	</tr>
@endforeach
CONTROLLER

$bookingsGoingOut = Booking::where('pickUpDate', '=', $today)->with('services')->paginate(15);
0 likes
2 replies
vermajnv's avatar

can you please print the result for $booking->services

vermajnv's avatar
vermajnv
Best Answer
Level 1

As I can see you are using belongsToMany relationship which will give multiple services for a single booking

BOOKING MODEL

public function services()
{
	return $this->belongsToMany('App\Service'); 
}

So I think you need to apply an extra iteration on $booking->services.

Like this

@foreach ($bookingsGoingOut as $booking)
    @foreach (optional($booking->services) as $service)
	<tr>
		<td class="border px-4 py-2">{{ $service->description }}</td>
	</tr>
    @endforeach
@endforeach

Hope this will help you!

Please or to participate in this conversation.