Created
May 14, 2025 16:58
-
-
Save Gkiokan/7fce64295514551cbd33a658d4a9d0e8 to your computer and use it in GitHub Desktop.
Laravel 12 Custom Paginator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
public function boot(): void | |
{ | |
$this->app->bind( | |
\Illuminate\Pagination\LengthAwarePaginator::class, | |
\App\Services\CustomLengthAwarePaginator::class | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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