im did a query for brand of car and the model but when i did added a
query to price range (whereBetwen) its not working
public function indexBrowse(Request $request)
{
$brand=$request->get('searchbrand');
$model=$request->get('searchmodel');
$searchtype=$request->get('searchtype');
$from=$request->get('pricefrom');
$to=$request->get('priecto');
$cars=car::where('brand', 'like', '%'.$brand.'%')
->where(function ($query) use ($model) {
$query->where('model','like','%'.$model.'%');
})->where(function ($query2) use ($from,$to) {
$query2->car::whereBetween('price',['%'.$from.'%','%'.$to.'%']);
})->get();
dd($cars);
$success = 'Results Car';
return view('cars.index', compact('cars', 'success'));
}
My Answer:
>input('brand');
$model=$request->input('model');
$minPrice=$request->input('minPrice');
$maxPrice=$request->input('maxPrice');
$cars = DB::table('cars')
->where('brand', $brand)
->where('model', $model)
->whereBetween('price', [$minPrice, $maxPrice])
->get();
return view('cars.index', compact('cars'));
}
Rate this post
4 of 5 based on 2819 votesComments