【问题标题】:Pagination Issue thru axio requestaxios请求的分页问题
【发布时间】:2020-03-10 01:13:12
【问题描述】:

我正在尝试向 laravel 后端发送 axio 获取请求

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 页得到结果..

你能告诉我如何解决这个问题....

【问题讨论】:

    标签: laravel pagination


    【解决方案1】:

    我找到了答案……

    我们必须使用 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",
    

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 2018-12-26
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 2020-05-31
      • 2019-11-20
      • 1970-01-01
      相关资源
      最近更新 更多