Level 50
$bookings is a collection, so you need to encode it to json in order to pass it to your Vue component:
<booking :bookings="{{ json_encode($bookings) }}"></booking>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to pass $bookings to a component through a BookingResource, in order to trigger eloquent relationships within the component.
Component
<booking :bookings="{{$bookings}}"></booking>
Controller
$bookings_ = Booking::all();
$bookings = BookingResource::collection($bookings_);
BookingResource
public function toArray($request)
{
return [
'name' => $this->user->name, // within component {{booking.user.name}}
];
}
It expects parameter 1 to be string, is there a way to get $booking_ through the resource?
Maybe this?
<booking :bookings="{{ $bookings->toJson() }}"></booking>
Please or to participate in this conversation.