I'm Using Laravel 10 I'm trying to get Random Record Without Duplication using inRandomOrder But It Giving Duplicate Record Some Time. help me to Solve It
My Controller Code
$Question = Question::inRandomOrder()->limit(50)->get();
To get random records without duplication using Laravel's inRandomOrder()
method, you can use distinct()
method to get unique records
$questions = Question::inRandomOrder()
->limit(50)
->distinct()
->get();