Php 按随机顺序排列

Php 按随机顺序排列,php,mysql,laravel,laravel-5,Php,Mysql,Laravel,Laravel 5,我问了一个问题,用这个代码总共回答了40道7215题 $questions = Question::where([ 'visible' => 'yes', 'deleted' => 'no' ]) ->inRandomOrder() ->take(40) ->get(); 但在某些情况下,我在这个查询中多次遇到同一个问题,有没有办法只回答一个问题?使用distinct尝试您的查询,但不确定它是否适用于inRandomOrde

我问了一个问题,用这个代码总共回答了40道7215题

$questions = Question::where([
    'visible' => 'yes',
    'deleted' => 'no'
])
    ->inRandomOrder()
    ->take(40)
    ->get();

但在某些情况下,我在这个查询中多次遇到同一个问题,有没有办法只回答一个问题?

使用distinct尝试您的查询,但不确定它是否适用于inRandomOrder:

$questions = Question::where([
'visible' => 'yes',
'deleted' => 'no'
])
->inRandomOrder()
->take(40)
->distinct()
->get();

使用distinct尝试您的查询,不确定它是否适用于inRandomOrder:

$questions = Question::where([
'visible' => 'yes',
'deleted' => 'no'
])
->inRandomOrder()
->take(40)
->distinct()
->get();

如果希望一次只回答一个问题,请将get替换为first()time@RahulMeshram每次执行此查询时,我需要得到40个不同的问题it@User154584:我想你可以在take之后尝试distinct()(40)用first()替换get如果你想一次只回答一个问题time@RahulMeshram每次执行此查询时,我需要得到40个不同的问题it@User154584:我想你可以在拍摄(40)后尝试使用distinct()