为了账号安全,请及时绑定邮箱和手机立即绑定

分页不适用于过滤器。点击第2页(带过滤器)将返回无过滤器的第2页

分页不适用于过滤器。点击第2页(带过滤器)将返回无过滤器的第2页

PHP
米脂 2021-05-05 21:42:42
我有分页问题。与过滤器一起使用时,只有第一页有效。控制器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)) {            $query->whereIn('category',$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)) {            $query->where('price','>=',$min_price)                ->where('price','<=',$max_price);        }        // filter brand        $brand = Input::has('brand')            ? Input::get('brand')            : ['Adidas','Nike','Puma','Mizuno','Umbro','Line 7'];        if (isset($brand)) {            $query->whereIn('brand',$brand);        }        // filter store        $store = Input::has('store')            ? Input::get('store')            : ['JD Sports Malaysia','SportsClick','Al-Ikhsan','Sports Wear','Sports Direct'];        if (isset($store)) {            $query->whereIn('store',$store);        }        //filter Gender        $gender = Input::has('gender')             ? Input::get('gender')             : ['Male','Female','None'];        if(isset($gender)){            $query->whereIn('gender',$gender);        }        $search = Input::get('query');        if (isset($search)) {            $query->where('product','like',"%$search%")                ->orWhere('brand', 'like', "%$search%")                ->orWhere('category', 'like', "%$search%")->get();        }    })->paginate(12);    return view('customer.category',compact('products'))->withProduct($products);}控制器代码是我获取过滤器输入的方式该视图是我如何显示分页链接2号及以上的页面应显示已过滤的产品
查看完整描述

1 回答

?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

更改$products->links();为 $products->appends($_GET)->links(),我想您会在链接中添加查询参数。


查看完整回答
反对 回复 2021-05-21
  • 1 回答
  • 0 关注
  • 110 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号