how to shuffle data in laravel?

Report
Question
718 views

You can shuffle data through collection or direct Eloquent

Please explain why do you think this question should be reported?

Report Cancel

laravel collection shuffle

$collection = collect([1, 2, 3, 4, 5]);

$shuffled = $collection->shuffle();

$shuffled->all();

eloquent shuffle

User::all()->random();
User::all()->random(10);

Thread Reply

Leave an comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>