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();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM