A common issue when working with Livewire pagination is experiencing a redirect to /livewire/update within pagination links when a component gets updated.
This is a really simple fix. Let's figure out what the problem is here first.
Imagine a component that lists out a bunch of transactions:
class TransactionsTable extends Component
{
public function render()
{
return view('livewire.transactions-table', [
'transactions' => Transaction::latest()->paginate(10),
]);
}
}
Here's the template:
<div>
<div>
<!-- Output stuff here, doesn't matter what/how -->
</div>
<div>
<!-- The pagination links -->
{{ $transactions->links() }}
</div>
</div>
The pagination here will work, but any time this component gets updated/refreshed, we'll see a redirect to /livewire/update for each pagination link.
You'll kick yourself if you've been stuck on this for a while. The issue is simply that we haven't included the WithPagination
trait.
use Livewire\WithPagination;
class TransactionsTable extends Component
{
use WithPagination;
public function render()
{
return view('livewire.transactions-table', [
'transactions' => Transaction::latest()->paginate(10),
]);
}
}
Pagination was still working because it used the paginator from Eloquent, as usual, to display the links. Here's what didn't work, though:
It's tricky because everything appears to be working on the surface due to Livewire using Blade.
Hope this helps!