Ad

Laravel Merge To Object And Create Pagination From That

- 1 answer

with this codes i can get all records from tables. but i want to merge this objects and create paginate from that, for example:

$total_legal_users = AccountLeaglUsers::all();
$total_real_users = AccountRealUsers::all();

create paginate, for example:

$total = $total_legal_users + $total_real_users;
$total->paginate(50);

how to do that?

My Test:

$results = $total_legal_users->union($total_real_users)->paginate(50);

but i get error for union

Ad

Answer

You can manually create a paginator.

$total_legal_users = AccountLeaglUsers::all()->toArray();
$total_real_users = AccountRealUsers::all()->toArray();
$total = array_merge($total_legal_users, $total_real_users);
$perPage = 15;
$paginator = new Illuminate\Pagination\Paginator($total, perPage);

And read about it more here

Ad
source: stackoverflow.com
Ad