laravel whereRaw查询错误

时间:2015-11-10 17:49:09

标签: php mysql laravel-5

这是我的MySQL查询,我转换为laravel,我收到以下错误请咨询如何修复

observer.onComplete

错误

Connection.php第651行中的QueryException:

$shiftData=   DB::table(DB::raw('shifts'))
    ->whereRaw("time_sheet_id = $getTimesheet1->time_sheet_id AND user_id = $user_id->user_id")
    ->whereRaw("$shift_start_time BETWEEN shift_start_time AND shift_end_time OR $shift_end_time BETWEEN shift_start_time AND shift_end_time OR $shift_start_time >= shift_start_time AND $shift_end_time <= shift_end_time")
    ->get();
  $shift_end_time = $request->input('shift_end_time');
$shift_start_time = $request->input('shift_start_time');

shift_atart和shift_end数据类型是“时间”

1 个答案:

答案 0 :(得分:0)

你的SQL查询看起来像一个伪代码

应在sql查询之前定义'shift start time'和'shift end time'。

尝试这样的事情:

$shift_end_time = $request->input('shift_end_time');
$shift_start_time = $request->input('shift_start_time');

$shiftData=   DB::table('shifts')
    ->where(time_sheet_id, $getTimesheet1->time_sheet_id)
    ->where(user_id, $user_id->user_id)
    ->whereBetween('shift_start_time', array($shift_start_time, $shift_end_time))
    ->whereBetween('shift_end_time', array($shift_start_time, $shift_end_time))
    ->where('shift_end_time', '>=', 'shift_start_time')
    ->get();