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