I have a list of vehicles in a mysql db and I'm building a query within my controller using laravel framework.
My problem is I have 2 columns (vehicle_price and discount_price)
I'm trying to return my result order by lowest price on up.
Because some values exist in the discount_price column I can't figure out how to return a list with the lowest prices ascending taking both columns into account.
You'd think perhaps I could test if there is a value in the discount_price, use that but no idea what to do.
fyi: when the discount_price column is 'empty' its a 0 (zero)
public function showUsed()
$vehicles = DB::table('used_vehicles')
->join('dealerships', 'used_vehicles.dealer_id', '=', 'dealerships.id')
->join('makes', 'used_vehicles.make_id', '=', 'makes.id')
->join('models', 'used_vehicles.model_id', '=', 'models.id')
->join('used_vehicles_categories', 'used_vehicles.category_id', '=', 'used_vehicles_categories.id')
->select('used_vehicles.*','dealerships.name','dealerships.address_street','dealerships.address_city','dealerships.address_province','dealerships.address_postal_code','dealerships.phone','dealerships.toll_free_phone','makes.name as make_name','models.model_name as model_name','used_vehicles_categories.category_title as category_name')
return view('/pages/used/index', ['vehicles' => $vehicles]);