我知道我可以通過一個簡單的點在Laravel中加載嵌套關(guān)系,但是我需要知道是否可以加載嵌套在資源中并在API中使用它,如下所示: public function toArray($request) {return [ 'Room' => AccommodationRoomResource::collection($this->firstrelation.NetstedRelation), ];我的第二個問題是我可以只加載其中的某些字段,因為我不需要加載所有數(shù)據(jù)并使它變得凌亂
1 回答

慕標(biāo)琳琳
TA貢獻1830條經(jīng)驗 獲得超9個贊
您需要的是“渴望加載”。有一個文檔。請參閱默認(rèn)情況下的“急切加載”部分。
簡而言之,您應(yīng)該$with
向模型添加屬性:
... protected $with = ['room']; /// given that relation name is 'room' ...
- 1 回答
- 0 關(guān)注
- 178 瀏覽
添加回答
舉報
0/150
提交
取消