laravel / lumen查询生成器whereColumn方法中的问题

时间:2017-12-19 06:01:24

标签: php laravel lumen

  • 流明版本:5.5
  • PHP版本:7.0

我编写了以下代码来使用whereColumn方法更新数据:

Ratings::whereColumn([['class_id', '=', $class_id], ['id', '=', $rating_id]])->update(['grade' => $grade, 'star' => $star, 'comment' => $comment]);

生成SQL错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'where clause' (SQL: update \`ratings\` set \`grade\` = 16级学生, \`star\` = 4, \`comment\` = very good where (\`class_id\` = \`1\` and \`id\` = \`6\`))

似乎正确的SQL命令应该使用引用''而不是“

有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

As per docs

  

whereColumn方法可用于验证两列是否相等

因此,它会尝试将列$ wget www.akshayud.me --2017-12-19 08:03:18-- http://www.akshayud.me/ Resolving www.akshayud.me (www.akshayud.me)... 151.101.1.147, 151.101.65.147, 151.101.129.147, ... Connecting to www.akshayud.me (www.akshayud.me)|151.101.1.147|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://akshayud.me/ [following] --2017-12-19 08:03:18-- http://akshayud.me/ Resolving akshayud.me (akshayud.me)... 162.255.119.148 Connecting to akshayud.me (akshayud.me)|162.255.119.148|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://www.akshayud.me/ [following] --2017-12-19 08:03:18-- http://www.akshayud.me/ Connecting to www.akshayud.me (www.akshayud.me)|151.101.1.147|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://akshayud.me/ [following] --2017-12-19 08:03:18-- http://akshayud.me/ Connecting to akshayud.me (akshayud.me)|162.255.119.148|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://www.akshayud.me/ [following] --2017-12-19 08:03:19-- http://www.akshayud.me/ Connecting to www.akshayud.me (www.akshayud.me)|151.101.1.147|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://akshayud.me/ [following] 与假设1作为列进行比较,请参阅后面的1 -

而是使用class_id功能

where

答案 1 :(得分:0)

请尝试此代码。

DB::table('table_name')->where('id','=',$request->input('id'))->update(['name'=>'jijo','address'=>'ernakulam']);