laravel,如何仅在最新记录中使用“ whereHas”

时间:2019-05-28 13:26:09

标签: php mysql laravel eloquent

我需要进行查询,以获取按ID分组的最后记录的数据,我有一个名为“活动”的表,另一个名为“植物”的表,我需要按plant_id和然后移动该活动的关系 enter image description here

这是我的查询

$plant=Plant::whereHas('activities.transfers.sections.greenhouses',function($q) use($id){
    $q->groupBy('activities.plant_id')
    ->where('greenhouses.location_id',$id);
    })->get();

但是,这是行不通的,我无法仅凭最近的活动进行雄辩地过滤,似乎雄辩地返回了所有这些活动

0 个答案:

没有答案