Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/WithPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@

trait WithPagination
{
public $page = 1;
public $pageNames = ['page'];

public function getQueryString()
{
return array_merge(['page' => ['except' => 1]], $this->queryString);
return array_merge(collect($this->pageNames)->mapWithKeys(fn($i) => [$i => ['except' => 1]]), $this->queryString);
}

public function initializeWithPagination()
{
$this->page = $this->resolvePage();
foreach ($this->pageNames as $pageName) {
$this->$pageName = $this->resolvePage();
}

Paginator::currentPageResolver(function () {
return $this->page;
Paginator::currentPageResolver(function ($pageName = 'page') {
return $this->$pageName;
});

Paginator::defaultView($this->paginationView());
Expand All @@ -35,35 +37,35 @@ public function paginationSimpleView()
return 'livewire::simple-' . (property_exists($this, 'paginationTheme') ? $this->paginationTheme : 'tailwind');
}

public function previousPage()
public function previousPage($pageName = 'page')
{
$this->setPage(max($this->page - 1, 1));
$this->setPage(max($this->$pageName - 1, 1));
}

public function nextPage()
public function nextPage($pageName = 'page')
{
$this->setPage($this->page + 1);
$this->setPage($this->$pageName + 1);
}

public function gotoPage($page)
public function gotoPage($page, $pageName = 'page')
{
$this->setPage($page);
$this->setPage($page, $pageName);
}

public function resetPage()
{
$this->setPage(1);
}

public function setPage($page)
public function setPage($page, $pageName = 'page')
{
$this->page = $page;
$this->$pageName = $page;
}

public function resolvePage()
public function resolvePage($pageName = 'page')
{
// The "page" query string item should only be available
// from within the original component mount run.
return request()->query('page', $this->page);
return request()->query($pageName, $this->$pageName);
}
}