Nested Select in Eloquent

  eloquent, laravel

I want to recreate below SQL in Eloquent.

I want to avoid DB::raw as I have logics behind the PartnerPrice::class (model)

select
    `partner_prices`.*,
    ROW_NUMBER () OVER (
        PARTITION BY group,
        TYPE
        ORDER BY
            effective_at DESC,
            created_at DESC
    ) r
from
    `partner_prices`
where
    `type` = 'premium'
    and `partner_id` = 8
    and `group` = 'premier'
    and `effective_at` <= '2020-10-31 00:00:00'

Source: Laravel

Leave a Reply