我有类似的搜索:
$users = User::search($q)
->orderBy($sortBy, $orderBy)
->paginate($perPage);
而且我可以使用]在刀片中对结果进行分页>
{{ $users->render() }}
没问题。但是我的SearchController继续像
if($request->loc){ $users = $users->where('loc',$request->loc); } if($request->sz) { $users = $users->where('sz',$request->sz); } ... return view('search', compact('users'));
这意味着我不能在刀片中使用{{$ users-> render()}},因为$ users没有该集合的orderBy,分页。
我该如何解决?感谢您的回答!
我的搜索类似:$ users = User :: search($ q)-> orderBy($ sortBy,$ orderBy)-> paginate($ perPage);我可以使用{{$ users-> render(...
您不应该将分页和过滤Collections结合使用,它会使结果变得平淡。如果要使用分页进行过滤,则必须在QueryBuilder
上进行。