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

kendrick's avatar

htmlspecialchars() expects parameter 1 to be string, object given

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?

0 likes
3 replies
manelgavalda's avatar

$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>
bugsysha's avatar
bugsysha
Best Answer
Level 61

Maybe this?

<booking :bookings="{{ $bookings->toJson() }}"></booking>

Please or to participate in this conversation.