Reaques-> get () второй страницы пусто, когда мы используем разбиение на страницы laravel - PullRequest
0 голосов
/ 16 сентября 2018

Я строю тест, я отображаю вопрос один за другим, используя simplepaginate of Laravel. Затем в моем контроллере я хочу получить то, что проверяется переключателем для каждого вопроса. Для первого вопроса это работает, но для других, когда я хотите получить запрос-> get ('question2') не существует, то же самое для вопросов 3 и 4.

Это мой взгляд:

<form method="post" id="questionnaire">
{{csrf_field()}}
                <span id="form_output"></span>
  @foreach($questions as $question)
    <h1>{{$question->question}}</h1>
    <?php $no= ($questions->currentpage()-1)* $questions->perpage() +1; ?>
<div class="contentform">
    <div id="sendmessage"> Your message has been sent successfully. Thank you. </div>


    <div class="leftcontact">

              <div class="form-group">
               <label class="container1">{{$question->choix1}}

                    <input type="radio" name="{{$no}}" id="radio"value="1">
                    <span class="checkmark"></span>
                     </label>

   </div> 

        <div class="form-group">
               <label class="container1">{{$question->choix2}}

                    <input type="radio" name="{{$no}}" id="radio" value="2"/>
                    <span class="checkmark"></span>
                     </label>

   </div> 

        <div class="form-group">
               <label class="container1">{{$question->choix3}}

                    <input type="radio" name="{{$no}}" id="radio"value="3"  />
                    <span class="checkmark"></span>
                     </label>

   </div>   

       <div class="form-group">
               <label class="container1">{{$question->choix4}}

                    <input type="radio" name="{{$no}}" id="radio"value="4"  />
                    <span class="checkmark"></span>
            </label>
   </div> 
   @endforeach
    <nav aria-label="Page navigation example test">
                    {!! $questions->links(); !!}
                  </nav> 
       <button type="submit" class="bouton-contact">Send</button>
    `</form>` 

Это мой контроллер:

class PassExam extends Controller
  {
public function showView(){
$questions=DB::table('questions')->where('id_examen',1)->orderBy('created_at', 'desc')->simplePaginate(1);
//  $questions=DB::table('questions')->where('id_examen',1)->orderBy('created_at', 'desc')->get();
$nb=1;
    return view('examen')->with(compact('questions'))
    ->with(compact('nb'));
}
public function result(Request $request){
    $questions=DB::table('questions')->where('id_examen',1)->orderBy('created_at', 'desc')->get();
    $nbcorrecte=0;
    $nberrone=0;
    $ch=null;
 $test="";
      $ii=1;

     $c=1;
    for($i=0;$i<4;$i++){

        $ch=$c++;
        $test=$test.$request->get($ch)."-"; 
        if($request->get($ch)==$questions[$i]->reponse_correcte)
        { $nbcorrecte++;  }
        else 
            {$nberrone++;}

    }
    $output = array('nberonne' => $nberrone,
                    'nbcorrecte'=>$nbcorrecte,
                    'test' =>$test,
     );
    echo json_encode($output);
}

Это функция ajax, которая выполняется при нажатии кнопки подтверждения:

<script  type="text/javascript">
    $(document).ready(function() {
       $('#questionnaire').on('submit', function(event){
           event.preventDefault();
          var form_data = $(this).serialize();
    $.ajax({
        url:"{{ route('questionaireresult') }}",
        method:"POST",
        data:form_data,
        dataType:"json",
        success:function(data)
        {
            /*if(data.error.length > 0)
            {
                var error_html = '';
                for(var count = 0; count < data.error.length; count++)
                {
                    error_html += '<div class="alert alert-danger">'+data.error[count]+'</div>';
                }
                $('#form_output').html(error_html);
            }
            else
            {*/
                $('#form_output').html(data.nberrone);
                alert('vous avez nberrone='+data.nberonne+"réponse correcte"+data.nbcorrecte+"  " +data.test);

        }
    })
});






      });
           </script>   

Для моих двух маршрутов это:

Route::get('/examen','PassExam@showView')->name('examen');
 Route::post('/questionaireresult','PassExam@result')->name('questionaireresult');

Можете ли вы помочь, как узнать, какой переключатель выбран на второй, третьей и четвертой страницах?

...