duandeng1824 2016-09-21 22:05
浏览 338
已采纳

Laravel 5 Eloquent Query Builder中单引号的语法错误

I've been trying to write a massive update query with a where clause, and I've found that Laravel 5.3 Eloquent Query Builder makes a syntax error.

The query is the following:

$query = $this->model
    ->where('state', "pending")
    ->whereRaw('created_at <= NOW() - INTERVAL 12 HOUR')
    ->update(['state' => "timeout"]);

Which is translated to this:

update `orders`
set `state` = timeout, `updated_at` = 2016-09-21 21:47:39
where `state` = pending and created_at <= NOW() - INTERVAL 12 HOUR

This query keeps failing since the values for the columns state and updated_at are not written with single quotes.

How can I force Laravel to write to put the single quotes correctly?

  • 写回答

2条回答 默认 最新

  • dongliechuich10319 2016-09-21 22:08
    关注

    Maybe try where('created_at', DB::raw('NOW() - ..'));

    And why are you putting peding in single quotes? Laravel escapes values automatically.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab