laravel 原生字段查询 whereRaw 和 where(DB::raw(''))

laravel whereRaw 和 where(DB::raw(''))

用 where(DB::raw(''))的时候,结尾会被增加一个莫名其妙的 is null()

用toSql()发现的,而使用whereRaw则不会

$student=DB::table("info")->whereRaw('id> ? and fenshu >= ?',[2,300])->get();//多个条件

建议使用laravel whereRaw

特别注意:函数中的$start变量需要加单引号

XcReservation::where(['status'=>1,'teacher_id'=>$teacherid])
    ->whereRaw("DATE_FORMAT(start_time,'%Y-%m-%d') >= '$start'")
    ->whereRaw("DATE_FORMAT(start_time,'%Y-%m-%d') <= '$end'")
    ->get();
原文地址:https://www.cnblogs.com/caibaotimes/p/13923514.html