Skip to content

Instantly share code, notes, and snippets.

@JulianMBr
Created March 2, 2021 23:51
Show Gist options
  • Save JulianMBr/bebedbc745b42748c8a9c6815ff6b73c to your computer and use it in GitHub Desktop.
Save JulianMBr/bebedbc745b42748c8a9c6815ff6b73c to your computer and use it in GitHub Desktop.
Extending the Livewire component to emit an event when changing the page.
<?php
namespace App\Helpers\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
class PaginatedComponent extends Component
{
use WithPagination;
public function previousPage()
{
$this->emit('pageChanged');
$this->setPage(max($this->page - 1, 1));
}
public function nextPage()
{
$this->emit('pageChanged');
$this->setPage($this->page + 1);
}
public function setPage($page)
{
$this->emit('pageChanged');
$this->page = $page;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment