I'm working on an e-commerce project and on the client side we have two 'sort by option' Cheapest and Expensive and for order I'm using the code below and it's ok!
$query->select([
'*',
DB::raw(
'IF(`discountPrice` IS NOT NULL, `discountPrice`, `price`) `sortPrice`',
),
])->orderBy('sortPrice', 'ASC')->paginate(15);
but I don't want the products with zero quantity to show up on the first if their price is high or low. they should be constantly on the bottom of the pagination if their quantity is 0;
any solutions?