laravel集合合并后保持分页

时间:2018-07-20 09:50:22

标签: laravel

合并不同的集合后,我需要保持分页,该集合具有相同的结构。

代码

 $allclients = collect();

 foreach($User as $user){
       $clients = Users::where('status', 'LIKE', $stat.'%')->orderBy('name')->paginate($this->pagination);
       if($allclients->isEmpty()){
                $allclients = $clients;
       }
       $allclients = $allclients->merge($clients);
 }

当我使用merge()时,我的分页消失了。

2 个答案:

答案 0 :(得分:0)

尝试一下:

$clients = Users::where('status', 'LIKE', $stat.'%')->orderBy('name')->paginate($this->pagination);
$clients = collect($clients->items());
$allclients = $allclients->merge($clients);

答案 1 :(得分:0)

我将$ stat更改为array(),删除了foreach

 $clients = Users::whereIn('status', $stat)->orderBy('name')->paginate($this->pagination);