I am trying to make Quiz application. I have more than 600 questions in various categories such as jp, sn, ei etc. Now I want to show the questions and options to users from various categories in randomly. But getting error. Would someone help me to do right. I tried something like this - In my Controller.php
public function index()
{
$jp = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'JP')->get();
$sn = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'SN')->get();
$ei = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'EI')->get();
$tf = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'TF')->get();
$equestions = array("$jp","$sn","$ei","$tf");
//dd($equestions);
return view('question.english.index', compact('equestions'));
}
And in my view index.blade.php
@foreach($equestions as $equestion)
<p>{{ $equestion->question }}</p>
<p>{{ $equestion->option1 }}</p>
<p>{{ $equestion->option2 }}</p>
@endforeach