Php Laravel:选择记录时比较两个表之间的日期时间

Php Laravel:选择记录时比较两个表之间的日期时间,php,laravel,query-builder,Php,Laravel,Query Builder,我有一个Laravel应用程序,我在其中检查线程注释(线程注释表)创建日期时间和线程(线程表)最后访问日期 我将选择如果任何线程注释创建日期时间>线程上次访问日期,我将查询它们。 这样做的目的是通知用户自上次访问线程以来有多少条新评论 下面是我的代码 $new_thread_comment_count = DB::table('ap_thread') ->join('ap_thread_comment', 'ap_thread_comment.ThreadID',

我有一个Laravel应用程序,我在其中检查线程注释(线程注释表)创建日期时间和线程(线程表)最后访问日期

我将选择如果任何线程注释创建日期时间>线程上次访问日期,我将查询它们。 这样做的目的是通知用户自上次访问线程以来有多少条新评论

下面是我的代码

$new_thread_comment_count = DB::table('ap_thread')
            ->join('ap_thread_comment', 'ap_thread_comment.ThreadID', '=', 'ap_thread.ThreadID')
            ->where('ap_thread.CreatedBy', Auth::user()->UserID)
            ->where('ap_thread_comment.CreatedDateTime','>','ap_thread.last_visit_date')
            ->count();
我的问题是,这不起作用。如果我将操作数更改为,请使用

$new_thread_comment_count = DB::table('ap_thread')
            ->join('ap_thread_comment', 'ap_thread_comment.thread_id', '=', 'ap_thread.thread_id')
            ->whereRaw('ap_thread_comment.created_at > ap_thread.last_visit_date')
            ->where('ap_thread.created_by','=',Auth::user()->user_id)
            ->Count();

您将创建的日期与身份验证的id进行比较?否。我会根据登录的用户进行选择,以及ap_thread_注释和ap_thread表之间的日期时间。我可以查看您的表吗?CreatedBy是创建记录的人…CreatedDateTime是创建记录的时间,因此它应该是
->where('ap_thread.CreatedBy',auth::user()->CreatedBy)
$new_thread_comment_count = DB::table('ap_thread')
            ->join('ap_thread_comment', 'ap_thread_comment.thread_id', '=', 'ap_thread.thread_id')
            ->whereRaw('ap_thread_comment.created_at > ap_thread.last_visit_date')
            ->where('ap_thread.created_by','=',Auth::user()->user_id)
            ->Count();