2 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊
由于“附加”用于頂級(jí)數(shù)據(jù),因此請使用 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貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以使用 PHP 函數(shù)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 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)