0

I have union query ,

 $invoices = DB::table('invoices')
            ->select('id', 'client_id', 'created_at')
            ->where('client_id', '=', $id)
            ->whereNull('deleted_at');
    $payments = DB::table('payments')
            ->select('id', 'client_id', 'created_at')
            ->where('client_id', '=', $id)
            ->whereNull('deleted_at');
    return $invoices->union($payments)
                    ->orderBy('created_at', 'asc')
                    ->get();

Here I want to apply pagination and laravel buil in pagination will not be supported. But I don't know about manual pagination and found one answer here manual pagination - stack question but I couldn't solve my issue.

Is there any other good tutorial which help me to learn manual pagination in laravel 5.1.

Please help me to implement pagination for above query?

Community
  • 1
  • 1
gsk
  • 2,329
  • 8
  • 32
  • 56
  • 2
    Asking for tutorials and other off-site resources is off topic on Stack Overflow, so asking for links to a tutorial should not be part of your question. Also, you linked to a manual pagination example from another question. That answer is pretty straight forward: pass a collection of items (which you get from your union), the total number of items per page (limit), the current page and any other options such as the url path and query string. Please explain what you don't understand as far as the implementation goes. – Bogdan Oct 25 '15 at 09:29
  • 1
    There's also [this answer](http://stackoverflow.com/questions/25338456/laravel-union-paginate-at-the-same-time) which shows how to use the paginator in the context of using a union. – Bogdan Oct 25 '15 at 09:35
  • yes.. it is working fine after adding slice.Your second link solved the issue..thank you – gsk Oct 25 '15 at 09:38

1 Answers1

1

Make some calculations and pass params to methods ->skip(100)->take(10)->get(), where skip and take works like LIMIT 100, 10

Denys Klymenko
  • 394
  • 5
  • 18