WithPerPagePagination.php
1 <?php 2 3 namespace App\Traits; 4 5 trait WithPerPagePagination 6 { 7 public $perPage = 10; 8 9 public function mountWithPerPagePagination() 10 { 11 $this->perPage = session()->get('perPage', $this->perPage); 12 } 13 14 public function updatedPerPage($value) 15 { 16 session()->put('perPage', $value); 17 } 18 19 public function applyPagination($query, $pageName = 'page') 20 { 21 return $query->paginate( 22 perPage: $this->perPage, 23 pageName: $pageName 24 ); 25 } 26 }