我有搜索结果,视图中也有分页器,但是当我单击页面时,它返回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'));
}
有什么主意吗?
............................................... ................................................... ................................................... ................................................... ...........
答案 0 :(得分:0)
您在第一部分中使用Eloquent,在第二部分中使用查询构建器,并且append是一种雄辩的方法,您从查询构建器收到的集合与雄辩的Eloquent的集合不同。相同的方法...