Skip to content

Instantly share code, notes, and snippets.

@Shaz3e
Created July 21, 2024 15:29
Show Gist options
  • Save Shaz3e/fca61f81e21e4106941c58aa57ecf046 to your computer and use it in GitHub Desktop.
Save Shaz3e/fca61f81e21e4106941c58aa57ecf046 to your computer and use it in GitHub Desktop.
Pagination with Livewire without loosing serial number
// 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