我的数据如下:$completes = Complete::with(['answers', 'survey.location'])->orderBy('created_at', 'DESC')->get();
如何将所有completes
放在survey.location = 1
?
我尝试过像Location::where()->with('completes')
之类的操作,但我需要completes
订购,而不是按location
分组
答案 0 :(得分:2)
试试这个:
$completes = Complete::with('answers')
->whereHas('survey', function ($query) {
$query->where('location','=',1);
})
->orderBy('created_at', 'DESC')->get();
有关详细信息,请查看Constraining Eager Loads部分中的Doc:)