第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 Laravel 5.7 中,如何處理作為集合的子集合的集合?

在 Laravel 5.7 中,如何處理作為集合的子集合的集合?

PHP
紅糖糍粑 2022-07-09 18:30:24
如何在 Laravel 5.7 中返回集合的子集合?我有一個(gè) Laravel 集合,它本身包含一個(gè)集合。當(dāng)我通過我的 api 返回父集合時(shí),顯然有一個(gè)“子”對(duì)象,但是當(dāng)我嘗試返回“子”對(duì)象時(shí)它為空。相關(guān)收藏代碼:$item =  [  'id' => $this->id,  ...  $this->mergeWhen($this->type === Item::[type], [     ...     'children' => [type]::collection($this->[prop])  ]),...return $item;];相關(guān)api控制器代碼:$itemsQuery = $[parent_type]->items()->topLevel()->withAll()->ordered()->get();$items = [type]::collection($itemsQuery);$return_array = [];foreach ($items as $item){           array_push($return_array, $item);  }    return $return_array;這將返回我所期望的。"data": {    "id": [guid],    ...    "children": [     {       "id": [guid],       ...     }  ]}但是當(dāng)我把它改成$itemsQuery = $[parent_type]->items()->topLevel()->withAll()->ordered()->get();$items = [type]::collection($itemsQuery);$return_array = [];foreach ($items as $item){           array_push($return_array, $item->children);  }    return $return_array;我明白了"data": null
查看完整描述

1 回答

?
慕后森

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

嘗試這個(gè) :


...


$return_array = collect();


foreach ($items as $item)

{         

  $return_array->push($item->children); 

}    


return $return_array->toArray();


查看完整回答
反對(duì) 回復(fù) 2022-07-09
  • 1 回答
  • 0 關(guān)注
  • 156 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)