亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將其他數據傳遞給拉拉維爾資源

將其他數據傳遞給拉拉維爾資源

PHP
米琪卡哇伊 2022-09-17 17:19:33
我需要將我的自定義數據傳遞到相同級別的資源數組,但它會脫離數組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()),                ]            ]);輸出
查看完整描述

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()),

                ]

            ]);


查看完整回答
反對 回復 2022-09-17
?
人到中年有點甜

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));


查看完整回答
反對 回復 2022-09-17
  • 2 回答
  • 0 關注
  • 131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號