File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
src/Illuminate/Database/Eloquent Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -478,14 +478,18 @@ public function find($id, $columns = ['*'])
478
478
}
479
479
480
480
/**
481
- * Retrieve a random model instance or a collection of instances.
481
+ * Retrieve one or more random model instances.
482
482
*
483
483
* @param int $count
484
484
* @param array $columns
485
- * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null
485
+ * @return \Illuminate\Database\Eloquent\Model|null| \Illuminate\Database\Eloquent\Collection
486
486
*/
487
- public function findRand (int $ count = 1 , array $ columns = ['* ' ])
487
+ public function findRandom (int $ count = 1 , array $ columns = ['* ' ])
488
488
{
489
+ if ($ count < 1 ) {
490
+ return $ this ->newModelInstance ()->newCollection ();
491
+ }
492
+
489
493
return $ count === 1
490
494
? $ this ->inRandomOrder ()->first ($ columns )
491
495
: $ this ->inRandomOrder ()->limit ($ count )->get ($ columns );
You can’t perform that action at this time.
0 commit comments