php - Pagination Not Working With filter. Click page 2(with filter) will return to Page 2 with no filter


I have problem with pagination. while using it with filter, only the first page is working.


public function create(Request $request)
    $products = Product::where(function($query) {
        //  filter category
        $category = Input::has('category')
            ? Input::get('category')
            : ['Clothes','Pants','Equipments','Shoes','Gears'];

        if (isset($category)) {

        // filter price
        $min_price = Input::has('min_price') ? Input::get('min_price') : 1 ;
        $max_price = Input::has('max_price') ? Input::get('max_price') : 999 ;
        if (isset($min_price) && isset($max_price)) {

        // filter brand
        $brand = Input::has('brand')
            ? Input::get('brand')
            : ['Adidas','Nike','Puma','Mizuno','Umbro','Line 7'];

        if (isset($brand)) {

        // filter store
        $store = Input::has('store')
            ? Input::get('store')
            : ['JD Sports Malaysia','SportsClick','Al-Ikhsan','Sports Wear','Sports Direct'];

        if (isset($store)) {

        //filter Gender
        $gender = Input::has('gender') 
            ? Input::get('gender') 
            : ['Male','Female','None'];


        $search = Input::get('query');

        if (isset($search)) {
                ->orWhere('brand', 'like', "%$search%")
                ->orWhere('category', 'like', "%$search%")->get();

    return view('customer.category',compact('products'))->withProduct($products);


<!-- store bottom filter -->
<div >
  <span >Showing {{$products->count()}} Result(s)</span>
      {!! $products->links();!!} 
<!-- /store bottom filter -->

The controller code is how I get the filter input

and the view is how I display the pagination link

the page for number 2 and above should display the filtered product




Change$products->links(); to$products->appends($_GET)->links(), I think you will get the query parameters added in links.

People are also looking for solutions to the problem: NGINX config for php backend and JS frontend


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.