laravel select 5 random rows from the 20 most recent rows ( without mapping after load & do with one query )

  eloquent, laravel, laravel-8, mysql, php

how i can do this

Ex : select 5 random rows from the 20 most recent row

I need do this with eloqunet and get data with query from db not with mapping data

I found this query but i cant convert this to laravel eloqunet …

Query :

select tbl1.* from (select *from DemoTable ORDER BY ShippingDate DESC LIMIT 20 ) as tbl1
-> ORDER BY RAND() LIMIT 5;

Source: Laravel

Leave a Reply