如何解决Laravel-过滤来自另一个sql表的结果
现在我具有捕获事件的功能(它也会提供参与者ID),但是我还有另一个表 参与者编号为participator_id的我,我需要按状态对其进行过滤
public function eventSearch(Request $request)
{
return ParticipantEvent::with('participant')
->where('end_date','>=',Carbon::now())
->get()
->map(function($event) {
$event->url = route('public::participant::show',['participant' => $event->participant]);
$participant = collect($event->participant->toArray())->all();
return $event;
});
}
我有解决方案来吸引参加者,状态为:
$participants = Participant::where(
function ($query) {
$query->whereHas(
'participantElections',function ($subQuery) {
$subQuery->where('status','=','good');
}
)
}
)->get();
return $participants;
但是如何结合这两种解决方案?
解决方法
我想您可能需要在with()
子句上添加一个闭合过滤器
ParticipantEvent::with([
'participant' => function ($query) {
$query->whereHas(
'participantElections',function ($subQuery) {
$subQuery->where('status','=','good');
}
)
}
])
->where('end_date','>=',Carbon::now())
->get()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。