Created
March 2, 2021 23:51
-
-
Save JulianMBr/bebedbc745b42748c8a9c6815ff6b73c to your computer and use it in GitHub Desktop.
Extending the Livewire component to emit an event when changing the page.
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
<?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