Belisario Peró
Belisario Peró

Reputation: 637

Laravel - Nest Collection into parent key

I need to create JSON Data from Laravel Collection. I have a collection that returns pictures records. I need to nest this collection which has multiple items into a higher key called photos and then convert into Json (toJson() function will be enough I believe)

This is my Collection result and I need to append this into a higher key called photos

enter image description here

Can anyone help me please? Regards!

Upvotes: 0

Views: 121

Answers (1)

Andy Song
Andy Song

Reputation: 4684

Say you had a variable called $photos.

   dd(collect(['photos' => $photos]));

Upvotes: 1

Related Questions