Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel查询中添加条件?(拉威尔5.3)_Php_Laravel_Repository_Laravel 5.3_Laravel Query Builder - Fatal编程技术网

Php 如何在laravel查询中添加条件?(拉威尔5.3)

Php 如何在laravel查询中添加条件?(拉威尔5.3),php,laravel,repository,laravel-5.3,laravel-query-builder,Php,Laravel,Repository,Laravel 5.3,Laravel Query Builder,我在UserRepository.php中的函数如下: public function displayList($year, $subaccountcode = NULL) { $query = Self::orderBy('programcode') ->orderBy('accountcode') ->findWhere(['year' => $year]) if(isset

我在UserRepository.php中的函数如下:

public function displayList($year, $subaccountcode = NULL)
{
    $query = Self::orderBy('programcode')
                 ->orderBy('accountcode')
                 ->findWhere(['year' => $year])
            if(isset($subaccountcode))
                 ->findWhere(['subaccountcode' => $subaccountcode]);
            else
                ;
    return $query;
}
我添加了一个条件来检查子帐户代码是否存在。我试图喜欢它,但存在错误:

 2/2 ReflectionException in Container.php line 809: Class App\Repositories\UserRepository does not exist 
如何解决错误

更新


我正在使用第三方软件包。我从这里得到:

这取决于
findWhere()
的功能。如果它类似于
find()
,并返回一个对象,但不是查询生成器的实例,则执行以下操作:

$query = Self::orderBy('programcode')->orderBy('accountcode')->findWhere(['year' => $year]);

if (isset($subaccountcode)) {
    $query->findWhere(['subaccountcode' => $subaccountcode]);
}

return $query;

$Subaccountcode
是否存在,
->findWhere(['year'=>$year])
必须保持运行存在错误:
1/1 Macroable.php第74行中的BadMethodCallException:方法findWhere不存在
@mosestoh此方法在Laravel中不存在,我以为它的方法是由您定义的。如果您确实定义了它,请说明您是如何定义的。如果没有,请使用
where()
而不是
findWhere()
return$query->get()public function displayList($year,$subaccountcode=NULL){$query=Self::orderBy('programcode')->orderBy('accountcode')->findWhere(['year'=>$year]);return$query;}
,它可以工作。但当我添加条件if时,它不是working@mosestoh当你使用第三方软件包时,你应该在问题中这样说。很抱歉,我对andersao/l5存储库不熟悉。我建议您编辑您的问题并添加此信息,也许其他人可以帮助您。