php - How to orderBy a calculated column in Laravel Eloquent? -


i have products talbes has columns price1, price2, etc. want order table 1 - (price1 / price2) , select 10 records 11th row.

how can achieve select *, 1 - (price1 / price2) discount products order discount in laravel eloquent?

currently i'm using accessor calculate discount , using sortby order entire product collection, means if need 10 reocrds, have select entire table first. have ~20k records, approach extremely slow (took ~10s on 1cpu , 0.5gb ram vps). i'm thinking calculate discount in query rather using accessor. know how in eloquent? thanks.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -