【发布时间】:2019-04-29 22:29:55
【问题描述】:
我有我的搜索结果我的视图中也有我的分页器,但是当我点击页面时它返回 404 错误。
我试过这个:
1- @include('front.partials.pagination', ['paginator' => $products])
2- {{$products->appends(Request::except(['page','_token']))->links() }}
3- {{$products->appends(request()->query())->links() }}
4- $products->appends(['brands' => $brandss]); //in contoller
所有的结果都一样404 Error
这是我的完整功能:
public function advancedsearch(Request $request) {
// dd($request->all());
$options = Specification::whereHas('subspecifications')->with(['subspecifications' => function($query){
$query->status('Active');
}])->get();
$brandss = Input::has('brands') ? Input::get('brands') : [];
$suboption = Input::has('suboptions') ? (int)Input::get('suboptions') : [];
$min_price = Input::has('min_price') ? (int)Input::get('min_price') : null;
$max_price = Input::has('max_price') ? (int)Input::get('max_price') : null;
//codes
if(!empty($request->input('brands')) && !empty($request->input('min_price')) && !empty($request->input('max_price'))){
$products = Product::
where('price', '>=', $min_price)
->where('price', '<=', $max_price)
->whereIn('brand_id', $brandss)
->paginate(12);
$products->appends(['brands' => $brandss, 'suboptions' => $suboption, 'min_price' => $min_price, 'max_price' => $max_price]);
}
elseif(!empty($request->input('suboptions')) && !empty($request->input('min_price')) && !empty($request->input('max_price'))){
$products = DB::table('products')
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : [];
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->where('products.price', '>=', $min_price)
->where('products.price', '<=', $max_price)
->paginate(12);
$products->appends(['brands' => $brandss, 'suboptions' => $suboption, 'min_price' => $min_price, 'max_price' => $max_price]);
}
//
elseif(!empty($request->input('brands')) && !empty($request->input('suboptions'))){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : [];
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->paginate(12);
$products->appends(['brands' => $brandss, 'suboptions' => $suboption]);
}
elseif(!empty($request->input('brands')) && !empty($request->input('suboptions')) && !empty($request->input('min_price')) && !empty($request->input('max_price'))){
$products = DB::table('products')
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : [];
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->where('products.price', '>=', $min_price)
->where('products.price', '<=', $max_price)
->whereIn('products.brand_id', $brandss)
->paginate(12);
$products->appends(['brands' => $brandss, 'suboptions' => $suboption, 'min_price' => $min_price, 'max_price' => $max_price]);
}
//
elseif(!empty($request->input('suboptions'))){
$products = DB::table('products')
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : [];
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->paginate(12);
$products->appends(['suboptions' => $suboptions]);
}
elseif(!empty($request->input('brands'))){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
$products->appends(['brands' => $brandss]);
}
elseif($request->has('min_price') && $request->has('max_price')){
$products = DB::table('products')
->whereBetween('price', [$min_price, $max_price])
->paginate(12);
$products->appends(['min_price' => $min_price, 'max_price' => $max_price]);
}
return view('front.advancesearch', compact('products', 'options'));
}
有什么想法吗?
.................................................. ..................................................... ..................................................... ..................................................... ......
【问题讨论】:
-
你用的是哪个 laravel 版本?
-
@EmtiazZahid 5.6
-
分页链接 URL 怎么样?你检查了吗?
-
@sadaiMudiNaadhar 即将到来,就像
site.com?brands[]=1&page=2
标签: php laravel pagination