[英]Laravel: Unknown column $parameter in 'on clause'
I have troubles with using a parameter in a DB query and parameter binding in Laravel. 我在使用数据库查询中的参数和Laravel中的参数绑定时遇到麻烦。
I get this error: 我收到此错误:
Error: "Column not found: 1054 Unknown column '3' in 'on clause'"
This is the part of a query: 这是查询的一部分:
->join('foo AS f1', function($join) use ($bar)
{
$join->on('f1.foo', '=', 'f2.foo')
->on('f1.bar', '=', $bar);
})
If I do this instead, it works: 如果我改为这样做,它将起作用:
->on('f1.bar', '=', DB::raw($bar));
What's the solution to this? 有什么解决方案? I would like to use parameter binding for this as well of course.
我当然也想为此使用参数绑定。 However, when I do:
但是,当我这样做时:
->on('f1.bar', '=', ':bar', ['bar' => $bar]);
I get this: 我得到这个:
ErrorException in Grammar.php line 196:
Array to string conversion
when you connecting two tables with join you must specify the column names ($bar must be equal to column name string). 当使用join连接两个表时,必须指定列名($ bar必须等于列名字符串)。 So if you want to send some parameters data you must use
where
instead on
. 因此,如果要发送一些参数数据,则必须使用
where
代替on
。
->join('foo AS f1', function($join) use ($bar)
{
$join->on('f1.foo', '=', 'f2.foo')
->where('f1.bar', '=', $bar);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.