laravel - 通过 axio 请求的分页问题
问题描述
我正在尝试向 laravel 后端发送 axio fetch 请求
url = /search?searchBy=product_id&searchValue=sprint-10
Route::get('/search', 'ProductController@search');
public function search(Request $request){
$requestQuery = $request->query(); //to get all the queries
$searchBy = $request->searchBy;
$searchValue = $request->searchValue;
if( $searchBy == 'product_id' && $searchValue == true ) {
$product = Product::where("product_id", 'like', "%$searchValue%")->paginate(5);
return response($product);
} else {
return $requestQuery;
}
}
这将返回带有分页选项的产品......当我点击 next_page_url 时,它会转到
next_page_url: " http://sprint/search?page=2 ",
我没有从第 2 页得到结果..
你能告诉我如何解决这个问题....
解决方案
我找到了答案...
我们必须使用 appends($request->except('page'));
$product = Product::where("product_id", 'like', "%$searchValue%")->paginate(5);
return $product->appends($request->except('page'));
结果 :
next_page_url: "http://sprint-laravel/search?searchBy=product_id&searchValue=sprint-10&page=2",
推荐阅读
- typescript - 如果子类不调用父类的覆盖函数,我该怎么做,TypeScript 会抛出错误
- python - 创建唯一项目的 df 和每个唯一项目的另一列的最大值
- python - 有没有办法比较存储的值和用户的输入以删除 django 视图中的重复项?
- facebook - 无法将 Facebook 评论插件添加到网站
- python - ImportError:pycurl:libcurl 链接时 ssl 后端(schannel)不包括编译时 ssl 后端(openssl)
- javascript - 如何在 Formik 的选项标签的值中传递对象?
- python - 通过实现 Python、RabbitMQ、NodeJS 向网站显示消息
- r - 在 R 的数字数据框中使用函数 na_ma
- windows - 我可以指定一个不是正方形或矩形的特定非客户区吗?
- sql - 我想减少 SQL SELECT SUM 重复聚合