当前关系:
诊所可能没有顾问,顾问可能没有治疗。我只想返回诊所,has
的顾问,其中的has
治疗,其中包括与$treatment_id
相匹配的治疗(因此has
存在检查)。
当前尝试(返回0结果):
clinic::whereHas('consultants.treatments', function ($query) use ($treatment_id) {
$query->where('treatment_id', $treatment_id);
})
->paginate(10);
我觉得我需要一个whereHas
在whereHas
函数中,首先确定顾问是否有治疗方法,但是,如果这个逻辑是正确的,我如何在函数中处理它。
我期待返回3个结果,但目前是0。
我怎样才能做到这一点?非常感谢。
发布于 2017-07-18 09:56:57
因为它对许多人来说,应该是:
Clinic::whereHas('consultants.treatments', function ($query) use ($treatment_id) {
$query->where('id', $treatment_id);
})
->paginate(10);
https://stackoverflow.com/questions/45173935
复制相似问题