Laravel条件查询不会按预期返回结果我在条件为真时添加 whereIn 子句。如果我删除if语句然后它的返回结果按预期但在将此条件子句添加到查询
时不起作用这是我的代码:
<img src="https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg" alt="Mountain View" width="500" height="377">
<img src="https://i2.wp.com/beebom.com/wp-content/uploads/2016/01/Reverse-Image-Search-Engines-Apps-And-Its-Uses-2016.jpg?resize=640%2C426" alt="Mountain View" width="500" height="377">
这是查询日志
$cf = $request->session()->get('filter');
$designs = DB::table('designs');
$count = DB::table('designs');
$appFilters = $request->session()->get('filter');
if($request->session()->has('filter')){
$stringFilter = $this->filterIntToString($appFilters);
$fid = array_unique($this->fillterSearchEngine($appFilters));
$designs->whereIn('fid', $fid);
$count->whereIn('fid', $fid);
}
$stringFilter = [];
$sizeFilters = $request->session()->get('filSize');
$nsf = [];
foreach ($sizeFilters as $str) {
$str = str_replace('-', ',', $str);
array_push($nsf, $str);
}
$designs->orderBy('created_at', 'desc');
$designs->whereIn('o_size', $nsf);
$designs->where('cat', $c);
$designs->where('sub', $s);
$designs->take(16);
$results = $designs->get();
$count->whereIn('o_size', $sizeFilters)->where('cat', $c)->where('sub', $s);
$counts = $designs->count();
$html = view('app-pages.designs-filter-ajax')->with('stringFilter', $stringFilter)->with('appFilter', $appFilters)->with('designs', $results)->render();
return ['success', $html, $counts, count($results)];
答案 0 :(得分:0)
首先检查使用var_dump在$ appFilters中获取数据的天气,如果不是从会话中获取变量的错误