I have some problems with the collection of laravel. I have written the API and its shows like that:
[
[
{
"id": 1,
"name": "Zel",
"age": 43
},
{
"id": 2,
"name": "ZE",
"age": 4
}
]
]
I want to remove [] to show the data like:
[
{
"id": 1,
"name": "Zel",
"age": 43
},
{
"id": 2,
"name": "ZE",
"age": 4
}
]
I have tried many solutions I found on the internet but no one working so does anyone know how to show the data as an example help me pls!!!
CodePudding user response:
try this
$collection = $collection->flatten() ;
take a look at the Official documentation