2 回答
TA贡献1777条经验 获得超10个赞
由于“附加”用于顶级数据,因此请使用 instaed。concat
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()),
]
]);
TA贡献1895条经验 获得超7个赞
您可以使用 PHP 函数array_merge()
$categories = Category::whereNull('parent_id')->get()->toArray();
$merged = array_merge($categories, [
[
'id' => 9999,
'name' => 'How Offers',
'image' => 'http://businessdotkom.com/storage/categories/January2020/1o6nDi1kjVuwje5FiFXv.png',
'products' => ProductIndexResource::collection(Product::whereNotNull('sale_price')->get()),
]
]);
return CategoryProductsResource::collection(collect($merged));
- 2 回答
- 0 关注
- 111 浏览
添加回答
举报