i need to pass My custom data to the same level of array of resource but it goes out of array
JavaScript
x
return CategoryProductsResource::collection(Category::whereNull('parent_id')->get())
->additional([
'data' => [
'id' => 9999,
'name' => 'How Offers',
'image' => 'http://businessdotkom.com/storage/categories/January2020/1o6nDi1kjVuwje5FiFXv.png',
'products' => ProductIndexResource::collection(Product::whereNotNull('sale_price')->get()),
]
]);
Advertisement
Answer
Because additional is for top-level data, use concat
instaed.
JavaScript
return CategoryProductsResource::collection(Category::whereNull('parent_id')->get())
->concat([
'data' => [
'id' => 9999,
'name' => 'How Offers',
'image' => 'http://businessdotkom.com/storage/categories/January2020/1o6nDi1kjVuwje5FiFXv.png',
'products' => ProductIndexResource::collection(Product::whereNotNull('sale_price')->get()),
]
]);