phplaravellaravel-5illuminate-containerlaravel-pagination

Laravel's Illuminate paginator can't find query string


I'm working on a old PHP project, that is running in legacy SQL query, which is good but I like to use query builders like Laravel Illuminate SQL package!

So i have added all required package dependencies to run Illuminate SQL, and this query builder seems to work fine with pagination!

$users = Capsule::table('users')->paginate(1)->toArray();

But, the paginator seems not to be able to listen the query string! For example, by running the above code it would give some properties like, next_page , previous_page etc...

enter image description here

And when I try to pass the query string in the URL it can't fetch the data from query string(From the GET request)!

Visiting this page http://app.app/?page=2 would give the same result set.

How i should configure the Illuminate sql package so it can also listen to the query strings?

EDIT

Also, i've tried to use the illuminate/http package, but the $request->all() method always returns an empty array! Here is the code:

<?php
  require_once './vendor/autoload.php';
  use \Illuminate\Http\Request;

  $req = new Request();

  echo '<pre>';
  print_r($req->all());
  echo '</pre>';

It returns empty input data array, enter image description here

What i am missing to use the http package, any idea would be helpful.


Solution

  • You have to set a page resolver:

    \Illuminate\Pagination\Paginator::currentPageResolver(function ($pageName = 'page') {
        return (int) ($_GET[$pageName] ?? 1);
    });
    

    Laravel uses this resolver.