›
byrcsc/laravel-payrex · 1.x
Read one result page, stream all pages, or build a Laravel cursor paginator.
PayRex list endpoints use resource IDs as before and after cursors.
Laravel PayRex provides three levels of pagination: one response page, a
generator across every page, and Laravel's CursorPaginator.
The following resources support all three forms:
Customer payment methods and payout transactions return a single Listing
page and accept manual cursor arguments.
Use list() when the application controls the cursor:
$page = Payrex::customers()->list(
limit: 25,
after: $request->string('after')->toString() ?: null,
);
foreach ($page as $customer) {
// ...
}
$page->data;
$page->hasMore;
$page->first();
$page->collect();
$page->isEmpty();
count($page);The raw response is available on $page->raw. To construct the next manual
cursor, read the final resource ID when hasMore is true:
$last = $page->data[array_key_last($page->data)] ?? null;
$nextAfter = $page->hasMore ? $last?->id : null;autoPaging() returns a lazy generator. It fetches another page only as the
loop reaches it:
foreach (Payrex::customers()->autoPaging(limit: 100) as $customer) {
SyncCustomer::dispatch($customer->id);
}This is appropriate for jobs and console commands. Avoid turning a large generator into an array unless the complete result comfortably fits in memory.
paginate() bridges a PayRex list to Laravel's cursor paginator:
$customers = Payrex::customers()->paginate(
perPage: 20,
);
return view('customers.index', compact('customers'));In Blade:
@foreach ($customers as $customer)
<p>{{ $customer->name }}</p>
@endforeach
{{ $customers->links() }}The default query parameter is cursor. Supply a custom name or path when a
page contains more than one paginator:
$customers = Payrex::customers()->paginate(
perPage: 20,
cursorName: 'customers',
path: route('customers.index'),
);The package uses PayRex's has_more value instead of requesting one extra row,
so the outbound limit remains exactly the requested page size.
Use the trailing options array for documented list filters not modeled by a named parameter:
$page = Payrex::checkoutSessions()->list(
limit: 25,
options: [
'status' => 'active',
'customer_reference_id' => 'acct_1042',
],
);The same options are sent on every page of autoPaging() and paginate().