Eloquent查询构建器 - 来自哪里'是null'?

时间:2016-08-09 13:02:43

标签: laravel eloquent laravel-5.2

这是查询:

$allTests = \DB::connection('tars-test')
->table('tars-test.uut_result')
->select(\DB::raw('max(`START_DATE_TIME`)'))
->from('uut_result')
->where(\DB::raw("date(`START_DATE_TIME`) = '$date'"))
->where('uut_serial_number', $test->UUT_SERIAL_NUMBER)
->toSql();

这是输出:

"select max(`START_DATE_TIME`) from `uut_result` where 
date(`START_DATE_TIME`) = '2016-08-09' is null and `uut_serial_number` = ?"

来自哪个“是空”?

2 个答案:

答案 0 :(得分:0)

此行没有第二个参数:

->where(\DB::raw("date(`START_DATE_TIME`) = '$date'"))

将其分解为:

->where(\DB::raw('date(`START_DATE_TIME`)'), $date)

并且有效

答案 1 :(得分:0)

->where(\DB::raw("date(`START_DATE_TIME`) = '$date'"))

将位置更改为-> whereRaw

->whereRaw(\DB::raw("date(`START_DATE_TIME`) = '$date'"))