title: Laravel and a While Loop
body: <p>I'm new to Laravel and at the moment I have a piece of code in a Controller which without the <code>while</code> loop it works, it retrieves my query from the database.</p>
  
  <pre><code>public function dash($id, Request $request) {
          $user = JWTAuth::parseToken()-&gt;authenticate();
          $postdata = $request-&gt;except('token');
  
          $q = DB::select('SELECT * FROM maps WHERE user_id = :id', ['id' =&gt; $id]);
  
          if($q-&gt;num_rows &gt; 0){
              $check = true;
  
              $maps = array();
              while($row = mysqli_fetch_array($q)) {
                  $product = array(
                      'auth' =&gt; 1,
                      'id' =&gt; $row['id'],
                      'url' =&gt; $row['url'],
                      'locationData' =&gt; json_decode($row['locationData']),
                      'userData' =&gt; json_decode($row['userData']),
                      'visible' =&gt; $row['visible'],
                      'thedate' =&gt; $row['thedate']
                  );
                  array_push($maps, $product);
              }
          } else {
              $check = false;
          }
  
          return response()-&gt;json($maps);
      }
  </code></pre>
  
  <p>I am trying to loop through the returned data from <code>$q</code> and use <code>json_decode</code> on 2 key/val pairs but I can't even get this done right.</p>