我有一个收藏
$questions = ExaminationQuestion::where('question_set_id', $set->id)
->where('marks', array_flip($marks)['2 Marks'])
->inRandomOrder()
->get();
它的科目能力、化学、数学、英语、物理存储为 0、1、2、3、4。
[
{
id: 1,
question_set_id: 1,
subject: 0,
},
{
id: 2,
question_set_id: 1,
subject: 0,
},
{
id: 1,
question_set_id: 1,
subject: 1,
},
{
id: 2,
question_set_id: 1,
subject: 1,
},
{
id: 1,
question_set_id: 1,
subject: 2,
},
{
id: 2,
question_set_id: 1,
subject: 2,
},
{
id: 1,
question_set_id: 1,
subject: 3,
},
{
id: 2,
question_set_id: 1,
subject: 3,
},
{
id: 2,
question_set_id: 1,
subject: 4,
},
{
id: 2,
question_set_id: 1,
subject: 4,
},
]
我想通过不改组每个问题而是改组主题来以随机顺序显示 $questions 。就像以随机顺序显示所有数学问题然后以随机顺序显示所有物理问题等等。科目可以按任何顺序随机排列,但问题不应该像先显示一个 Aptitude 问题然后显示另一个英语问题那样随机排列。它应该像这样或以任何顺序显示,但要根据主题。
[
{
id: 1,
question_set_id: 1,
subject: 3,
},
{
id: 2,
question_set_id: 1,
subject: 3,
},
{
id: 1,
question_set_id: 1,
subject: 2,
},
{
id: 2,
question_set_id: 1,
subject: 2,
},
{
id: 1,
question_set_id: 1,
subject: 0,
},
{
id: 2,
question_set_id: 1,
subject: 0,
},
{
id: 1,
question_set_id: 1,
subject: 4,
},
{
id: 2,
question_set_id: 1,
subject: 4,
},
{
id: 2,
question_set_id: 1,
subject: 1,
},
{
id: 2,
question_set_id: 1,
subject: 1,
},
]
胡说叔叔