title: Laravel 5.6 How to take datas by id and print 10 by 10
body: <p>I was printing 50 questions yea it was working as well. But requirement changed how to take questions by topic_id and print them by 10 by 10 in 5 pages. Good news. I took topic_id and questions. But how do i take from Database in Controller.</p>
  
  <p><strong>My Database Column = Question</strong></p>
  
  <pre><code>| id | topic_id |question_text|
  | ---|:--------:|:-----------:|
  | 1  |     5    | question1   |
  | 2  |     6    | question2   |
  | 3  |     7    | question3   |
  </code></pre>
  
  <p><strong>topic_id => request of questions number</strong></p>
  
  <pre><code>array:9 [▼
  "_token" =&gt; "N6AJGDf95iQ5WOae3WKibS3yiEdzXJmW7RPXu6sE"
  1 =&gt; "5"
  2 =&gt; "3"
  3 =&gt; "5"
  4 =&gt; "1"
  5 =&gt; "3"
  6 =&gt; "6"
  7 =&gt; "7"
  8 =&gt; "8"
  ]
  </code></pre>
  
  <p><strong>It was my old Controller</strong></p>
  
  <pre><code>$questions = $request-&gt;input('questions');
  $inquiries = $request-&gt;input('inquiries');
  $queries = $request-&gt;input('queries');
  $examinations = $request-&gt;input('examinations');
  $inquisitions = $request-&gt;input('inquisitions');
  
  $except = [];
  
  $questions = Question::inRandomOrder()-&gt;limit(10)-&gt;get();
  $except = array_merge($except, $questions-&gt;pluck('id')-&gt;toArray());
  $inquiries = Question::inRandomOrder()-&gt;whereNotIn('id', $except)-&gt;limit(10)-&gt;get(); 
  $except = array_merge($except, $inquiries-&gt;pluck('id')-&gt;toArray())
  $queries = Question::inRandomOrder()-&gt;whereNotIn('id', $except)-&gt;limit(10)-&gt;get();
  $except = array_merge($except, $queries-&gt;pluck('id')-&gt;toArray());
  $examinations = Question::inRandomOrder()-&gt;whereNotIn('id', $except)-&gt;limit(10)-&gt;get();
  $except = array_merge($except, $examinations-&gt;pluck('id')-&gt;toArray());
  $inquisitions = Question::inRandomOrder()-&gt;whereNotIn('id', $except)-&gt;limit(10)-&gt;get();
  
  foreach ($questions as &amp;$question) {
    $question-&gt;options = QuestionsOption::where('question_id', $question-&gt;id)-&gt;inRandomOrder()-&gt;get();
  }
  return view('exams.create', compact('questions','inquiries','queries','examinations','inquisitions'));
  </code></pre>
  
  <p><strong>create.blade.php</strong></p>
  
  <pre><code>&lt;form method="post" name="myform" action="{{ route('exams.store') }}"&gt;
  {{ csrf_field() }}
  
  &lt;div id="account_details"&gt;
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          Нэгдүгээр хэсэг
      &lt;/div&gt;
      &lt;?php //dd($questions) ?&gt;
  @if(count($questions) &gt; 0)
      &lt;div class="panel-body"&gt;
      &lt;?php $i = 1; ?&gt;
      @foreach($questions as $question)
          @if ($i &gt; 1) &lt;hr /&gt; @endif
          &lt;div class="row"&gt;
              &lt;div class="col-xs-12 form-group"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;strong&gt;Асуулт {{ $question-&gt;id }}.&lt;br/&gt;&lt;br/&gt;{!! nl2br($question-&gt;question_text) !!}&lt;/strong&gt;&lt;br/&gt;
  
                      &lt;input
                          type="hidden"
                          name="questions[{{ $question-&gt;id }}]"
                          value="{{ $question-&gt;id }}"&gt;
                  @foreach($question-&gt;options as $option)
                      &lt;br&gt;
                      &lt;label class="radio-inline"&gt;
                          &lt;input
                              type="radio"
                              name="answers[{{ $question-&gt;id }}]"
                              value="{{ $option-&gt;id }}"&gt;
                          {{ $option-&gt;option }}
                      &lt;/label&gt;
                  @endforeach
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;?php $i++; ?&gt;
      @endforeach
      &lt;/div&gt;
  @endif
  &lt;/div&gt;&lt;input type="button" value="Дараагын хуудас" onclick="show_next('account_details','user_details','bar1');"&gt;
  &lt;/div&gt;
  
  &lt;div id="user_details"&gt;
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          Хоёрдугаар хэсэг
      &lt;/div&gt;
      &lt;?php //dd($questions) ?&gt;
      @if(count($inquiries) &gt; 0)
      &lt;div class="panel-body"&gt;
      &lt;?php $i = 1; ?&gt;
      @foreach($inquiries as $question)
          @if ($i &gt; 1) &lt;hr /&gt; @endif
          &lt;div class="row"&gt;
              &lt;div class="col-xs-12 form-group"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;strong&gt;Асуулт {{ $question-&gt;id }}.&lt;br/&gt;&lt;br/&gt;{!! nl2br($question-&gt;question_text) !!}&lt;/strong&gt;&lt;br/&gt;
  
                      &lt;input
                          type="hidden"
                          name="questions[{{ $question-&gt;id }}]"
                          value="{{ $question-&gt;id }}"&gt;
                  @foreach($question-&gt;options as $option)
                      &lt;br&gt;
                      &lt;label class="radio-inline"&gt;
                          &lt;input
                              type="radio"
                              name="answers[{{ $question-&gt;id }}]"
                              value="{{ $option-&gt;id }}"&gt;
                          {{ $option-&gt;option }}
                      &lt;/label&gt;
                  @endforeach
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;?php $i++; ?&gt;
      @endforeach
      &lt;/div&gt;
  @endif
  &lt;/div&gt;
  &lt;input type="button" value="Өмнөх хуудас" onclick="show_prev('account_details','bar1');"&gt;
  &lt;input type="button" value="Дараагын хуудас" onclick="show_next('user_details','qualification','bar2');"&gt;
  &lt;/div&gt;
  
  &lt;div id="qualification"&gt;
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          Гуравдугаар хэсэг
      &lt;/div&gt;
      &lt;?php //dd($questions) ?&gt;
      @if(count($queries) &gt; 0)
      &lt;div class="panel-body"&gt;
      &lt;?php $i = 1; ?&gt;
      @foreach($queries as $question)
          @if ($i &gt; 1) &lt;hr /&gt; @endif
          &lt;div class="row"&gt;
              &lt;div class="col-xs-12 form-group"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;strong&gt;Асуулт {{ $question-&gt;id }}.&lt;br/&gt;&lt;br/&gt;{!! nl2br($question-&gt;question_text) !!}&lt;/strong&gt;&lt;br/&gt;
  
                      &lt;input
                          type="hidden"
                          name="questions[{{ $question-&gt;id }}]"
                          value="{{ $question-&gt;id }}"&gt;
                  @foreach($question-&gt;options as $option)
                      &lt;br&gt;
                      &lt;label class="radio-inline"&gt;
                          &lt;input
                              type="radio"
                              name="answers[{{ $question-&gt;id }}]"
                              value="{{ $option-&gt;id }}"&gt;
                          {{ $option-&gt;option }}
                      &lt;/label&gt;
                  @endforeach
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;?php $i++; ?&gt;
      @endforeach
      &lt;/div&gt;
  @endif
  &lt;/div&gt;
      &lt;input type="button" value="Өмнөх хуудас" onclick="show_prev('user_details','bar1');"&gt;
      &lt;input type="button" value="Дараагын хуудас" onclick="show_next('qualification','exort','bar2');"&gt;
  &lt;/div&gt;
  
  &lt;div id="exort"&gt;
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          Дөрөвдүгээр хэсэг
      &lt;/div&gt;
      &lt;?php //dd($questions) ?&gt;
      @if(count($examinations) &gt; 0)
      &lt;div class="panel-body"&gt;
      &lt;?php $i = 1; ?&gt;
      @foreach($examinations as $question)
          @if ($i &gt; 1) &lt;hr /&gt; @endif
          &lt;div class="row"&gt;
              &lt;div class="col-xs-12 form-group"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;strong&gt;Асуулт {{ $question-&gt;id }}.&lt;br/&gt;&lt;br/&gt;{!! nl2br($question-&gt;question_text) !!}&lt;/strong&gt;&lt;br/&gt;
  
                      &lt;input
                          type="hidden"
                          name="questions[{{ $question-&gt;id }}]"
                          value="{{ $question-&gt;id }}"&gt;
                  @foreach($question-&gt;options as $option)
                      &lt;br&gt;
                      &lt;label class="radio-inline"&gt;
                          &lt;input
                              type="radio"
                              name="answers[{{ $question-&gt;id }}]"
                              value="{{ $option-&gt;id }}"&gt;
                          {{ $option-&gt;option }}
                      &lt;/label&gt;
                  @endforeach
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;?php $i++; ?&gt;
      @endforeach
      &lt;/div&gt;
  @endif
  &lt;/div&gt;
  
  &lt;input type="button" value="Өмнөх хуудас" onclick="show_prev('qualification','bar1');"&gt;
  &lt;input type="button" value="Дараагын хуудас" onclick="show_next('exort','wex','bar2');"&gt;
  
  &lt;/div&gt;
  
  &lt;div id="wex"&gt;
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          Тавдугаар хэсэг
      &lt;/div&gt;
      &lt;?php //dd($questions) ?&gt;
      @if(count($inquisitions) &gt; 0)
      &lt;div class="panel-body"&gt;
      &lt;?php $i = 1; ?&gt;
      @foreach($inquisitions as $question)
          @if ($i &gt; 1) &lt;hr /&gt; @endif
          &lt;div class="row"&gt;
              &lt;div class="col-xs-12 form-group"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;strong&gt;Асуулт {{ $question-&gt;id }}.&lt;br/&gt;&lt;br/&gt;{!! nl2br($question-&gt;question_text) !!}&lt;/strong&gt;&lt;br/&gt;
  
                      &lt;input
                          type="hidden"
                          name="questions[{{ $question-&gt;id }}]"
                          value="{{ $question-&gt;id }}"&gt;
                  @foreach($question-&gt;options as $option)
                      &lt;br&gt;
                      &lt;label class="radio-inline"&gt;
                          &lt;input
                              type="radio"
                              name="answers[{{ $question-&gt;id }}]"
                              value="{{ $option-&gt;id }}"&gt;
                          {{ $option-&gt;option }}
                      &lt;/label&gt;
                  @endforeach
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;?php $i++; ?&gt;
      @endforeach
      &lt;/div&gt;
  @endif
  &lt;/div&gt;
  
  &lt;input type="hidden" name="torol" value="1"&gt;
  
  &lt;div class="form-group"&gt;
  &lt;input type="button" value="Өмнөх хуудас" onclick="show_prev('exort','bar1');"&gt;
  &lt;button type="submit"&gt;Дуусгах&lt;/button&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>ExamsController@create</strong></p>
  
  <p>this is it. cause I need to take inputs requests of question arrays.</p>
  
  <pre><code>@foreach($questions as $question)
          @if ($i &gt; 1) &lt;hr /&gt; @endif
          &lt;div class="row"&gt;
              &lt;div class="col-xs-12 form-group"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;strong&gt;Асуулт {{ $question-&gt;id }}.&lt;br/&gt;&lt;br/&gt;{!! nl2br($question-&gt;question_text) !!}&lt;/strong&gt;&lt;br/&gt;
  
                      &lt;input
                          type="hidden"
                          name="questions[{{ $question-&gt;id }}]"
                          value="{{ $question-&gt;id }}"&gt;
                  @foreach($question-&gt;options as $option)
                      &lt;br&gt;
                      &lt;label class="radio-inline"&gt;
                          &lt;input
                              type="radio"
                              name="answers[{{ $question-&gt;id }}]"
                              value="{{ $option-&gt;id }}"&gt;
                          {{ $option-&gt;option }}
                      &lt;/label&gt;
                  @endforeach
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;?php $i++; ?&gt;
      @endforeach
  </code></pre>