following is my fluent query
$products = \DB::table('products')
->where(function($query) use ($title, $category_id, $brand_id, $type, $price_max, $price_min, $division_id, $district_id, $user_id, $is_active) {
if ($title)
$query->where('title', 'like', '%' . $title . '%');
if ($category_id)
$query->where('category_id', $category_id);
if ($type != NULL)
$query->where('type', $type);
if ($brand_id)
$query->where('brand_id', $brand_id);
if ($price_max) {
$query->whereBetween('price',[0,$price_max]);
}
else if ($price_min){
$query->whereBetween('price',[$price_min,1000000]);
}
else if ($price_min && $price_min){
$query->whereBetween('price',[$price_min,$price_max]);
}
if ($division_id)
$query->where('division_id', $division_id);
if ($district_id)
$query->where('district_id', $district_id);
if ($user_id)
$query->where('user_id', $user_id);
if ($is_active || $is_active == 'p') {
if ($is_active == 'p') {
$is_active = 0;
}
$query->where('is_active', '=', $is_active);
}
})
->orderBy($order_by, $order)
->paginate(10);
it is not working for price_min and price max parameter. if I avoid it rest of the query works fine. What I am doing wrong? Thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire