我尝试从数据库中获取事件
$eventWithDatas = Event::with(['persons' => function($query) {
$query->select('persons.id', 'name', 'title', 'status')
->where('date_of_death', null);
}, 'persons.health_items' => function($query) {
$query->select('id', 'name', 'date_in', 'date_end', 'person_id');
}])->get();
我想过滤我的关系persons.health_items。
理想的情况是拥有这样的东西:
$eventWithDatas = Event::with(['persons' => function($query) {
$query->select('persons.id', 'name', 'title', 'status')
->where('date_of_death', null);
}, 'persons.health_items' => function($query) use ($eventWithDatas) {
$query->select('id', 'name', 'date_in', 'date_end', 'person_id')
->where('date_end', $eventWithDatas->end);
}])->get();
$eventWithDatas应该是我的查询的第一部分 ( Event::get)
结果示例:
[
{
/ event collection (contain just 1 item for example)
"title": "vaccines",
"start": "2020-07-24 01:00:00",
"end": "2020-07-24 01:00:00", // <----------- I WANT TO USE THIS DATA FOR FILTER persons.health_items.date_end (see bottom)
"persons": [
"id": 1,
"name": "Jeremy",
...
"health_items": [
{
"id": 14,
"name": "my health item",
"date_end": // <-------------------- DATA TO FILTER (see top) (2020-07-24 01:00:00)
}
]
]
}
]
你知道我该怎么做吗?
www说