在laravel中查找超过15天的日期

gupuwyp2  于 2021-06-21  发布在  Mysql
关注(0)|答案(3)|浏览(418)

如果交货日期超过15天,我需要显示比较交货日期,还需要显示track\u track\u status=0作为默认值
找不到错误列:“where子句”中的1054未知列“delivery\u date”+interval 15 day<now()”

$secondstatus = DB::table('registrations')
            ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
            ->select('ssi_tracks.ssi_track_id', 'address', 'model', 'chassis', 'delivery_date','ssi_tracks.track_second_status')
            ->where([["ssi_tracks.track_second_status", "=", 0]])
             ->orWhereRaw('registrations.delivery_date + INTERVAL 15 DAY <= NOW()')

            ->get();
bzzcjhmw

bzzcjhmw1#

只要做:

$secondstatus = DB::table('registrations')
            ->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
            ->select('ssi_tracks.ssi_track_id', 'address', 'model', 'chassis', 'delivery_date','ssi_tracks.track_second_status')
            ->where([["ssi_tracks.track_second_status", "=", 0]])
             ->orWhere('registrations.delivery_date', '<=', \DB::raw("NOW() - INTERVAL 15 DAYS")))    
            ->get();

问题是查询生成器将对表名进行别名,如果它位于 whereRaw

mspsb9vt

mspsb9vt2#

使用原始查询,如下所示:

$now = \Carbon\Carbon::now();

->orWhere(DB::raw(registrations.delivery_date + INTERVAL 15 DAY, "<=", $now))

检查它,如果它返回任何错误,请在此处进行响应。

gt0wga4j

gt0wga4j3#

使用 Carbon 和拉威尔在一起 orWhere 相反

->orWhere( 'delivery_date', '<=', Carbon::now()->subDays(15))

相关问题