Eloquent take 25 random out of 400 first rows laravel 5.2

Posted 1 year ago by eddieace

Hi I need to make an eloquent request with top 400 rows, and select 25 random.

Right now the query looks like this. I get the latest 400 rows

$result = Model::where('status', '=', 0)
    ->orderBy('id', 'desc')

I know that I can do something like this, but then it will take all rows with status 0 but I want 25 out of the top 400.

$result = Model::where('status', '=', 0)

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.