Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lara28580's avatar

Laravel paginate Cashier Invoices

I want to paginate my invoices from stripe. What I did is I used a Paginator like so

$invoices = auth()->user()->invoices();
$invoices = new Paginator($invoices, 2);

$invoices->withPath('/settings/invoices');

The problem is when I paginate the invoices only the first page gets loaded and if I click on next the page stays the same, so no further invoices are loaded.

View

{{ $invoices->links() }}

Normally it should work that way?

0 likes
3 replies
lara28580's avatar
lara28580
OP
Best Answer
Level 10

Solved it already thank you! Did it like so

$array = auth()->user()->invoices()->toArray();
      $total= count($array);
      $per_page = 10;
      $current_page = $request->input("page") ?? 1;
      $starting_point = ($current_page * $per_page) - $per_page;
      $array = array_slice($array, $starting_point, $per_page, true);

      $invoices = new Paginator($array, $total, $per_page, $current_page, [
          'path' => $request->url(),
          'query' => $request->query(),
      ]);

jimie's avatar

This is what I did and seems to be working fine:

$items = auth()->user()->invoices();

    $total = $items->count(); // Specify your total here

    $perPage = 10;

    $currentPage = LengthAwarePaginator::resolveCurrentPage();

    $currentItems = $items->slice(($currentPage - 1) * $perPage, $perPage)->values();

    $invoices = new LengthAwarePaginator(
        $currentItems, // The items for the current page
        $total,        // Total number of items
        $perPage,      // Items per page
        $currentPage,  // Current page number
        ['path' => LengthAwarePaginator::resolveCurrentPath()] // Path to append to pagination links
    );

    $invoices->appends($request->query());


    return view("invoices", compact("invoices"));

Please or to participate in this conversation.