I've Eloquent API Resource UserResource
. When I try run something like this code:
$users = User::paginate(10);
return UserResource::collection($users);
Response will be like this:
{
"data": [
{
"name": "Fatima Conroy",
"email": "[email protected]"
},
{
"name": "John Doe",
"email": "[email protected]"
}
]
}
How I can remove data
key or rename it the get something like this response?
[
{
"name": "Fatima Conroy",
"email": "[email protected]"
},
{
"name": "John Doe",
"email": "[email protected]"
}
]
To get all the data just use ->all()
UserResource::collection($users)->all()
You can see more in the official doc about collections where it's explained that using all()
gets you the the underlying array represented by the collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With