Laravel : How to randomize the query of the Quiz with choices

Solution 1:

You can do additional query conditions for the choices relationship:

$questions = quizQuestions::where('quiz_id', '=', $quiz_id)->with(['choices' => function($query){
    $query->inRandomOrder();
}])->inRandomOrder()->get();

https://laravel.com/docs/8.x/eloquent-relationships#constraining-eager-loads