I'm trying to subtract one column from another and sort by the new AS variable. I suspect my 'minus operation' isn't correct in my query. It fails with the message:
Unknown column 'used_vehicles.selling_price' in 'order clause'
My controller:
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.vehicle_price - used_vehicles.discount AS used_vehicles.selling_price')
->where('used_vehicles.archived', 0)
->orderBy('used_vehicles.selling_price', 'ASC')
->paginate(30);
return view('/pages/used/index', ['vehicles' => $vehicles]);
}
Any idea what is wrong?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire