我有来自两个不同查询的两个对象LengthAwarePaginator,我想合并它们以显示在同一页/表上。
一旦我合并了这两个对象,我就失去了大多数属性,比如元素的总数,并且不能使用Laravel 5的render()函数:
$final =$res_query_1->合并($res_query_2)
有什么想法吗?
发布于 2017-08-04 08:44:44
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;
}https://stackoverflow.com/questions/45476309
复制相似问题