Skip to content
Advertisement

Eloquent Sort By depend on the field

I have a query like this:

JavaScript

I want to sort the result but i have problem. if the result of withMin if null i want to sort it by another field (lets say ‘product.sale_price’). Or how can i make a new field, lets say ‘final_price’, if promotion_price is null use sale_price.

What i already tried:

add this after get()

JavaScript

the result still not sorted

JavaScript

Advertisement

Answer

use orderByRaw

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement