我正在尝试为我的搜索查询创建条件,当我使用此代码时出现此错误:我的代码:
$condition = null;
foreach (session()->get('filters') as $items)`
{
$condition .= "where(".$items['type'].",".$items['value'].")->";
}
$cars = Car::where('is_active','active')->$condition->get();
我的错误:
未定义属性:Illuminate \ Database \ Eloquent \ Builder :: $ where(city_id,1)
1 回答
如果要向现有查询添加方法,请使用
$query = Car::newQuery()
开始查询 . 然后将您的方法附加到该变量 .