Php 如何将in with()关系与父数据进行比较,如where has do

Php 如何将in with()关系与父数据进行比较,如where has do,php,laravel,eloquent,Php,Laravel,Eloquent,我提出这样的要求: Event::where('team_id', Auth::user()->currentTeam->id) ->whereHas('animals', function ($query) use ($decodedId) { $query->where('animals.id', $decodedId) ->whereHas('health_items', function ($query) {

我提出这样的要求:

Event::where('team_id', Auth::user()->currentTeam->id)
->whereHas('animals', function ($query) use ($decodedId) {
    $query->where('animals.id', $decodedId)
        ->whereHas('health_items', function ($query) {
            $query->whereColumn('date_end', 'events.end');
        });
})
多亏了
whereColumn
,我将我的数据
健康项目
与祖父母
事件的数据进行了比较

$query->whereColumn('date_end', 'events.end');
它起作用了

只有WhereHas,我的响应中没有关系数据(它只是过滤掉
事件

我试图通过添加一个
来做同样的事情,但它不起作用

Event::where('team_id', Auth::user()->currentTeam->id)
->with(['animals' => function($query) use ($decodedId) {
        $query->where('animals.id', $decodedId)
            ->with(['health_items' => function ($query) {
                $query->whereColumn('date_end', 'events.end');
            }]);
    }])
返回错误:未知列“events.end”

是否有方法使用
事件
表中的列筛选“健康项目”项目

多谢各位