Thanks for the revert @bobbybouwmann. In my Livewire project I used the session method to update the per page and added a lifecycle hook on the per page variable, as soon as the value will be updated, put the per page value in the sessions.
trait WithPerPagePagination
{
use WithPagination;
public $perPage = 10;
public function mountWithPerPagePagination()
{
$this->perPage = session()->get('perPage', $this->perPage);
}
public function updatedPerPage($value)
{
session()->put('perPage', $value);
}
public function applyPagination($query)
{
return $query->paginate($this->perPage);
}
}
Here is my updated code down below. I am trying to replicate the same above function in Laravel, Inertia, Vue. I have created a public variable for $perPage with a default value of 5. What I need to do now is, I need to link it to the drop down input. And after that as soon as I change the per page value, it should put the per page value in the session as I had done it in the previous project using session()->put('perPage', $value);
Class UserController extends Controller
{
public $perPage = 5;
public function index()
{
$this->perPage = session()->get('perPage', $this->perPage);
$query = User::select('id', 'name', 'email', 'role_id', 'created_at');
$users = $query->paginate($this->perPage);
return Inertia::render('Backend/Management/AudienceManagement/Users/Index', [
'users' => $users
]);
}
}