1

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')
    ->limit(400)
    ->get();

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)
    -inRandomOrder()
    ->limit(25)
    ->get();
Edvard Åkerberg
  • 2,181
  • 1
  • 26
  • 47

0 Answers0