2017-08-03 10 views
0

同じページ/テーブルに表示するためにマージしたい2つの異なるクエリから2つのオブジェクトLengthAwarePaginatorがあります。Laravel 5 Merge LengthAwarePaginator

とすぐに、私は2つのオブジェクトをマージして、私はそのような要素の合計としての特性のほとんどを失うことだし、Laravel 5レンダリング()関数を使用することはできません。

$決勝= $ res_query_1-を>マージ($ res_query_2)

答えて

0
public function merge(LengthAwarePaginator $collection1, LengthAwarePaginator $collection2) 
    { 
     $total = $collection1->total() + $collection2->total(); 

     $perPage = $collection1->perPage() + $collection2->perPage(); 

     $items = array_merge($collection1->items(), $collection2->items()); 

     usort($items, array($this, 'cmp')); 

     $paginator = new LengthAwarePaginator($items, $total, $perPage); 

     return $paginator; 
    }