title: Putting query inside a for loop with condition in laravel
body: <p>this is not duplicate but related to the topic <a href="https://stackoverflow.com/questions/51237087/query-inside-for-loop-in-laravel?noredirect=1#comment89453437_51237087">Query inside for loop in laravel</a></p>
  
  <p>Is this the correct code in laravel for putting query inside the loop</p>
  
  <pre><code>//controller
          public function dtrdata()
          {
              for($i=1;$i&lt;=$totalnumdays;$i++){
                  $query= DB::table('dtrrecords')
                  -&gt;where('dtrrecords.bio_id', $i)
              }
              return view('pages/admin.dtrdata', compact('query','i'));
          }
          //view
           @foreach($query as $row =&gt; $rows1)
              &lt;tr&gt;
                  &lt;td&gt;{{$rows1-&gt;AM_IN}}&lt;/td&gt;
              &lt;/tr&gt;
          @endforeach
  </code></pre>