Skip to content
Advertisement

how i can pagenate data in laravel?

i have 6825 invoices in data base i want to pagenate 10 records per page

and in blade i want links like this (Prev, 1 2 3 4 5 7 8 .. 78 (upto last) next)

the code which i am using now in controller

public function index()
    {
    $ids = [10 , 20 ,30 ]
    $invoices = Invoice::whereIn('user_id', $ids)->where($cond)->paginate(10);
    return view('approved_invoices', compact('invoices'));
}

and blade

<tbody>
              @foreach($invoices as $invoice)
               <tr>
                  <td> {{ $invoice->subtotal }}</td>
               </tr>
              @endforeach
</tbody

i am getting only 10 records form 6825 how i can show link pages?

Advertisement

Answer

You are missing links() method on your results, that’s why you are only getting 10 results. Add this after your foreach loop:

$invoices->links();

You can read more about pagination on official documentation.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement