我有一个SQL搜索,我使用Eloquent whereRaw,而不是paginatate结果 .
Proplem: 结果是分页的,如果我导航到下一页,结果将会消失,它只会"SELECT All "因为laravel的分页只发送?page = GET请求 .
码:
if (Input::has('city')) {
$query .= ' and city = '.Input::get('city');
}
if (Input::has('area')) {
$query .= ' and area = '.Input::get('area');
}
if (Input::has('sub_location')) {
$query .= ' and sub_location = '.Input::get('sub_location');
}
if (Input::has('rent')) {
$query .= ' and rent = '.Input::get('rent');
}
if (Input::has('price_min') && Input::has('price_max')) {
$query .= ' and price < '.Input::get('price_max').' and price >'.Input::get('price_min');
}
$listings = ListingDB::whereRaw($query)->paginate(5);
return View::make('page.index')->with('title','Home')->with('listings',$listings);
因此,当我导航到下一页时,所有输入都消失了,因为laravel仅使用?page = GET变量生成分页,我该如何解决?
谢谢 .
2 回答
您可以将查询字符串追加到分页链接
“附加分页链接
您可以使用appends方法添加到分页链接的查询字符串 . 例如,要将&sort = votes附加到每个分页链接,您应该进行以下调用以追加:
{! $ listings-> appends(['sort'=>'value']) - > links()!!}
因此,在您的情况下,如果您已应用城市和租金搜索,则需要添加此类分页链接
{! $ listings-> appends(['city'=>'london','rent'=> 5000]) - > links()!!}
这将解决您的问题 .