Laravel Pagination with POST request

How to paginate eloquent via a POST request instead of a GET request?

You may have been looking for this all over the internet!

But at, we always have an answer to many problems :-)

Check the below code, this is how you have to do it!

$validator = Validator::make($request->all(), [
    'online_offline' => 'nullable|boolean',
    'search' => 'nullable|string',
    'page' => 'integer',  <----this will be your page number

$users = User::select('users.*')
->orderBy('id', 'DESC')
->paginate(10, ['*'], 'page', $request->page);

Let's check this out further:

->paginate(10, [‘*'], ‘page', $request->page);

The first number is simply the number of returned results.

The [‘*'] and  ‘page' parameters should not be touched.

And finally, the $request->page is the page number sent via your POST request via your application front end.

Please leave us a comment if this fixed your issue!