I have a one question about the laravel 4 multiple search.
I have variables that need to be checked, it is empty or not and I want to know, is there any other method to do this?
So far, I tried to do like this, but this doesn't seem good enough.
The code:
public function postQuickSearch() {
$vehicle_manufacturer = Input::get('vehicle_manufacturer');
$vehicle_model = Input::get('vehicle_model');
$year_reg_from = Input::get('year_reg_from');
$year_reg_to = Input::get('year_reg_to');
$price_from = Input::get('price_from');
$price_to = Input::get('price_to');
if(!empty($year_reg_from) && !empty($year_reg_to)) {
$query = Seller::where('vehicle_manufacturer', 'LIKE', '%'. $vehicle_manufacturer .'%')->orWhere('vehicle_model', 'LIKE', '%'. $this->getModel($vehicle_model) .'%')->whereBetween('year_reg', array($year_reg_from, $year_reg_to))->get();
}
if(!empty($price_from) && !empty($price_to)) {
$query = Seller::where('vehicle_manufacturer', 'LIKE', '%'. $vehicle_manufacturer .'%')->orWhere('vehicle_model', 'LIKE', '%'. $this->getModel($vehicle_model) .'%')->whereBetween('price', array($price_from, $price_to))->get();
}
if(empty($price_from) && empty($price_to) && empty($year_reg_from) && empty($year_reg_to)) {
$query = Seller::where('vehicle_manufacturer', 'LIKE', '%'. $vehicle_manufacturer .'%')->orWhere('vehicle_model', 'LIKE', '%'. $this->getModel($vehicle_model) .'%')->get();
}
if($query->count()) {
$data = array(
'results' => $query
);
return View::make('auto.vehicle.search')->with($data);
}
return Redirect::route('home')->with('global', 'No results.');
}
Thanks for Your help. :)