how to select from subquery using query builder in laravel 5

please help me, i have query: SELECT * from (select * from products ORDER BY id DESC LIMIT 20) AS result ORDER BY discount DESC LIMIT 14

so, how to convert into query builder in laravel 5. tks!

1 answer

  • answered 2017-06-17 19:31 itepifanio

    Try something like:

    Products::orderBy('id', 'desc')->take(20)->orderBy('discount', 'desc')->take(14)->get();