Laravel搜索结果分页而未直接收集

问题描述 投票:0回答:1

我有类似的搜索:

$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(...

php laravel search
1个回答
0
投票

您不应该将分页和过滤Collections结合使用,它会使结果变得平淡。如果要使用分页进行过滤,则必须在QueryBuilder上进行。

© www.soinside.com 2019 - 2024. All rights reserved.