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

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

Laravel 急切加載 withTrashed

Laravel 急切加載 withTrashed

PHP
天涯盡頭無女友 2021-12-03 15:54:26
所以我有這條線OpportunityController@index()。public function index(){    $opportunities = Opportunity::with([        'customer',        'province',        'createdBy',        'closedBy',        'status',        'checkedLists',    ])->paginate();    return new ApiCollection($opportunities);}所有這些相關(guān)模型都在使用SoftDeletestrait。我發(fā)現(xiàn)如果那些模型被軟刪除了,它們就會變成null,你需要調(diào)用withTrashed(). 所以這是有效的。public function index(){    $opportunities = Opportunity::with([        'customer' => function ($query) {            return $query->withTrashed();        },        'status' => function ($query) {            return $query->withTrashed();        },        'province' => function ($query) {            return $query->withTrashed();        },        'createdBy' => function ($query) {            return $query->withTrashed();        },        'closedBy' => function ($query) {            return $query->withTrashed();        },        'checkedLists',    ])->paginate();    return new ApiCollection($opportunities);}但是有沒有更好(更短/推薦)的方法來做到這一點,而不是像這樣重復(fù)聲明函數(shù)?我試過Opportunity::withTrashed([...])->paginate()and Opportunity::with([...])->withTrashed()->paginate,兩者都不起作用,仍然返回空值。
查看完整描述

1 回答

?
楊__羊羊

TA貢獻1943條經(jīng)驗 獲得超7個贊

您可以在建立關(guān)系時聲明。


public function customer()

    {

        return $this->belongsTo(Customer::class, 'customer_id')->withTrashed();

    }


查看完整回答
反對 回復(fù) 2021-12-03
  • 1 回答
  • 0 關(guān)注
  • 611 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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