Php 对null Laravel调用成员函数prepare()
我试图使用函数添加where条件,但这会导致出现以下错误:Php 对null Laravel调用成员函数prepare(),php,laravel,pdo,eloquent,closures,Php,Laravel,Pdo,Eloquent,Closures,我试图使用函数添加where条件,但这会导致出现以下错误: Call to a member function prepare() on null in /vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connection.php line 327 如果删除where-tname部分,查询将运行得非常好 var_转储以下输出 <small>Repositories/TeamRepository.php:31:</
Call to a member function prepare() on null in /vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connection.php line 327
如果删除where-tname部分,查询将运行得非常好
var_转储以下输出
<small>Repositories/TeamRepository.php:31:</small><b>object</b(<i>Doctrine\DBAL\Driver\PDOConnection</i>)[<i>590</i>]</pre><pre class='xdebug-var-dump' dir='ltr'>
<small>Repositories/TeamRepository.php:36:</small><font color='#3465a4'>null</font>
我编辑了Builder.php,并使用以下代码使其工作,但显然编辑现有库不是解决方案
为什么在我使用闭包时$pdo变量会被设置为null,而在我不使用闭包时却可以正常工作?代码中包含
prepare()
?@YourCommonSense这是他的代码的第二部分`$query->Where(函数($a){$a->Where('tname','=','John's Team')->或者Where('tname','=','Mark's Team')); });`代码$param->where的第二部分没有设置为执行$query->get()的变量;可能会将其更改为$query=$query->where(函数($a…
?@B001ᛦ $query->get()进行DB调用,因此prepare()作为其中的一部分被调用。@Emad我试过了,但没有用。我还试过在$a->where之前插入一个return语句(但这也没有任何区别)
<small>Repositories/TeamRepository.php:31:</small><b>object</b(<i>Doctrine\DBAL\Driver\PDOConnection</i>)[<i>590</i>]</pre><pre class='xdebug-var-dump' dir='ltr'>
<small>Repositories/TeamRepository.php:36:</small><font color='#3465a4'>null</font>
$this->model->newModelQuery()
/**
* Add a basic where clause to the query.
*
* @param \Closure|string|array $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return $this
*/
public function where($column, $operator = null, $value = null, $boolean = 'and')
{
if ($column instanceof Closure) {
$column($query = $this->model->newModelQuery());
$this->query->addNestedWhereQuery($query->getQuery(), $boolean);
} else {
$this->query->where(...func_get_args());
}
return $this;
}