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
Post a Comment