2017-11-24 1 views
1
私はLaravel 5.5でアプリケーションを開発しています

でそれを使用しますRUN TESTではランダムな質問を生成します(5としましょう)。それらをユーザーに1つずつ提供したいと思います。AJAXでページを作成しました。そのユーザーは私がメト内TestControllerで質問Laravelは何を達成したいことは、そのユーザーがクリックで</p> <p>...それはテストシステムの一種である...乱数の静的な配列を取得し、ページネーション

のランダムなリストを取得することができています。..フォームを送信れるSUBMITに

をクリックしますD「exec_testは」同じメソッド内のコードに続いて

// get data 
    $data = array (
       'tests' => Test::select('id','code','name',DB::raw('duration_m * 60 as duration_m'),'questions','passing_score') 
           ->where('id','=',$test_id) 
           ->orderBy('code', 'asc') 
           ->paginate($this->page_limit), 
     'test_questions' => Question::select('questions.id','questions.question_header','questions.question_detail_local_url') 
           ->join('tests','tests.id','=','questions.test_id') 
           ->where('test_id','=',$test_id) 
           ->whereIn('questions.id',$q_id) 
           //->orderByRaw("RAND()") 
           //->take(4) 
           ->paginate($this->test_question_page_limit), 

     'test_answers' => Answer::select('id','answer_text_cleaned') 
           ->whereIn('question_id',$q_id) 
           ->get()      
); 


    // check for ajax requests 
    if ($request->ajax()) { 
    return view('/custom/test/run_test_quests', $data)->render(); 
    } 

    return view('/custom/test/run_test_info',$data); 

あるしかし、私は方法がわからない...これは、その特定のテストのために3つのランダムIDを取得します

// get random id 
    $q_id = Question::select('id') 
        ->where('test_id','=',$test_id) 
        //->where('id','=',114) 
        ->orderByRaw("RAND()") 
        ->take(3) 
        ->get(); 

ですその最初のクエリを静的にして、1ページ(1ページに1つずつ)をユーザーに提供することができますか?すべての質問に行くことができます

お願いしますか?

答えて

0

最初のページの改ページは1になりますが、URLにも指定されます。

はこれを試してみてください。

if($request->input('page') ==1) 
{ 
//code for first page 
}else{ 
//code for random 
} 

これは単なる提案です。申し訳ありませんが、私は間違った質問を理解した場合

+0

これは効率的ではない...各テストは異なる質問があります:( –

関連する問題

 関連する問題