单击分页链接时,我无法保留搜索参数。例如,如果搜索查询返回 40 条记录并且我有两个页面,单击第二页将返回完整记录集的第二页,而不仅仅是搜索返回的 40 条记录。
这是postIndex()
来自我的控制器:
public function postIndex(){
$validator = Validator::make(
Input::all(),
array('priceMin' => array('numeric'),
'priceMax' => array('numeric')
)
);
if ($validator->fails()){
return Redirect::to('items')->withInput()->withErrors($validator);
} else {
return Redirect::to('items')->withInput();
}
}
我的getIndex()
:
public function getIndex(){
$items= $this->retriever->getListings(Input::old(), 20);
return View::make('listings', array('items' => $items);
}
然后该retriever
对象遍历旧输入并找到所有有效的搜索参数,用它们查询数据库,并以指定的数量分页,在本例中为 20。
我尝试使用->appends()
,但数据不在Input::old()
其中,如果有 10 个搜索参数,它会生成一个糟糕的 url,因为它使用GET
而不是POST
. 如何将我的参数应用于分页链接?