Skip to content

Instantly share code, notes, and snippets.

@Gkiokan
Created May 14, 2025 16:58
Show Gist options
  • Save Gkiokan/7fce64295514551cbd33a658d4a9d0e8 to your computer and use it in GitHub Desktop.
Save Gkiokan/7fce64295514551cbd33a658d4a9d0e8 to your computer and use it in GitHub Desktop.
Laravel 12 Custom Paginator
<?php
// ...
public function boot(): void
{
$this->app->bind(
\Illuminate\Pagination\LengthAwarePaginator::class,
\App\Services\CustomLengthAwarePaginator::class
);
}
<?php
namespace App\Services;
use Illuminate\Pagination\LengthAwarePaginator;
class CustomLengthAwarePaginator extends LengthAwarePaginator
{
public function toArray()
{
return [
'current_page' => $this->currentPage(),
'data' => $this->items->toArray(),
'from' => $this->firstItem(),
'last_page' => $this->lastPage(),
'per_page' => $this->perPage(),
'to' => $this->lastItem(),
'total' => $this->total(),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment