Created
July 21, 2024 15:29
-
-
Save Shaz3e/fca61f81e21e4106941c58aa57ecf046 to your computer and use it in GitHub Desktop.
Pagination with Livewire without loosing serial number
This file contains 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
// In your livewire blade | |
@php | |
// Get the current page number, default to 1 if not set | |
$currentPage = $dataSet->currentPage(); | |
// Get the number of items per page | |
$perPage = $dataSet->perPage(); | |
// Calculate the starting index | |
$i = ($currentPage - 1) * $perPage + 1; | |
@endphp | |
// In your livewire component | |
public function render() | |
{ | |
$query = User::query(); | |
$dataSet = $query->paginate(10); | |
return view('livewire.user-list', [ | |
'dataSet' => $dataSet, | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment