Laravel的Illuminate分页器找不到查询字符串
我正在处理一个旧的PHP项目,该项目在旧版SQL查询中运行,这很好,但是我喜欢使用Laravel Illuminate SQL程序包之类的查询构建器!
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!
因此,我已经添加了运行Illuminate SQL所需的所有软件包依赖关系,并且此查询构建器似乎可以在分页中正常工作!
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();
但是,分页器似乎无法收听查询字符串!例如,通过运行上面的代码,它将提供一些属性,例如next_page,previous_page等...
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...
当我尝试在URL中传递查询字符串时,它无法从查询字符串中获取数据(来自GET请求)!
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)!
访问此页面http://app.app/?page=2
会得到相同的结果集.
Visiting this page http://app.app/?page=2
would give the same result set.
我应该如何配置Illuminate sql程序包,使其也可以侦听查询字符串?
How i should configure the Illuminate sql package so it can also listen to the query strings?
编辑
此外,我尝试使用illuminate/http
包,但是$request->all()
方法始终返回一个空数组!这是代码:
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,
我缺少使用http软件包的内容,任何想法都会有所帮助.
What i am missing to use the http package, any idea would be helpful.
您必须设置页面解析器:
You have to set a page resolver:
\Illuminate\Pagination\Paginator::currentPageResolver(function ($pageName = 'page') {
return (int) ($_GET[$pageName] ?? 1);
});
Laravel使用此解析器.
Laravel uses this resolver.