Level 61
You can see it here in the docs.
public function toArray($request)
{
return [
'data' => $this->collection,
'sum_of_products' => $codeToReturnTheSum,
];
}
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Is there any way to return api resouce like this:
"items": {
"sum_of_products": 10000,
"data": [
{
"product_id": 1,
"price": 50.000
},
{
"product_id": 1,
"price": 50.000
},
]
},
You can see it here in the docs.
public function toArray($request)
{
return [
'data' => $this->collection,
'sum_of_products' => $codeToReturnTheSum,
];
}
Please or to participate in this conversation.