我想過濾資料,第一個封閉是針對附件,第二個封閉是針對AdminAttachment
。 $data = UserSalary:: with(['userData','Attachments'=> function($query) use($id) {
$query->where('type', 3) 。
$query->where('application_id',$id) 。
}])->with(['AdminAttachments' => function($queryadminattachement) use($id) /span>{
$queryadminattachement->where('type', 3) 。
$queryadminattachement->where('application_id',$id) 。
}])->查找($id)。
但現在我只得到了附件資料,但AdminAttachment是空白的,但在我的資料庫中的資料是存在的,所以它必須回傳兩個附件的資料,因為搜索標準也是一樣的。 有什么解決辦法嗎
謝謝
uj5u.com熱心網友回復:
檔案中有一節Eager Loading Multiple Relationships
有時你可能需要在一次操作中急于加載幾個不同的關系。要做到這一點,只需向with方法傳遞額外的引數:
$books = AppBook::with(['author'/span>, 'publisher'/span>])-> get();
所以不要兩次呼叫with方法,只是添加新的陣列值。
uj5u.com熱心網友回復:
試試這個
$data = UserSalary:: with(['userData','Attachments','AdminAttachments'] )
-> where(function($handle) use($id) {
$handle-> whereHas('Attachments', function($query) use($id) {
$query->where('type', 3) 。
$query->where('application_id',$id) 。
})
->whereHas('AdminAttachments',function($queryadminattachement) use($id) /span>{
$queryadminattachement->where('type', 3) 。
$queryadminattachement->where('application_id',$id) 。
});
})
->find($id)。
謝謝你
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/320611.html
標籤:
