TheNastyPasty
TheNastyPasty

Reputation: 69

How to paginate invoices from stripe in laravel?

I want to paginate my invoices from stripe. I tried to do so with new Paginator in my controller.

Controller

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

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

Passed my $invoices variable to the view created pagination links like so

{{ $invoices->links() }}

The problem no invoices are loaded if I paginate. The page stays always the same... Maybe someone could help me here?

Output enter image description here

Upvotes: 0

Views: 759

Answers (3)

Naren
Naren

Reputation: 74

   use Illuminate\Pagination\Paginator;

   $invoices = auth()->user()->invoices();
   $invoices = new Paginator($invoices, 10);
   $invoices->setPath($request->url());

Upvotes: 0

TheNastyPasty
TheNastyPasty

Reputation: 69

$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(),
      ]);

Upvotes: 0

Mohammad.Kaab
Mohammad.Kaab

Reputation: 1105

As far as I know, the first item that should pass to Paginator class should be a collection, But you are passing the whole query to it. so it should be something like

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

Upvotes: 1

Related Questions