i need to pass My custom data to the same level of array of resource but it goes out of array
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.
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()), ] ]);