title: Laravel for loop return data in in array
body: <p>I have 1 brand and 2 branches in my database, I'm getting the sales data for each branch.</p>
  
  <pre><code>public function getCurrentSales($brandid){
  $branches = DB::table('gc_branch')-&gt;where('BRAND_ID', $brandid)
                                    -&gt;select('BRANCHID', 'BRANCHNAME')
                                    -&gt;get(); 
  
  for ($i=0; $i&lt;count($branches);$i++){
  $mtdnetsales= DB::table('st_sales')
  //query
  -&gt;select(DB::raw('sum(AMOUNT) as TOT')-&gt;get();
  
  $ytdnetsales= DB::table('st_sales')
  //query
  -&gt;select(DB::raw('sum(AMOUNT) as TOT')-&gt;get();
  
  
  $netsalesdata=[['BRANCHID' =&gt; $branches[$i]-&gt;BRANCHID, 'BRANCHNAME' =&gt;branches[$i]-&gt;BRANCHNAME, 'MTDNETSALES' =&gt;$mtdnetsales[0]-&gt;TOT, 'YTDNETSALES' =&gt;$ytdnetsales[0]-&gt;TOT]];
  
  }//end for
  
  return $netsalesdata;
  </code></pre>
  
  <p>My problem is : </p>
  
  <ul>
  <li>if I put the return <code>$netsalesdata</code> in the for loop, I get the first raw only (1 branch only)</li>
  <li>if I put it outside the loop, i get the last row(the second branch only) , while my database has 2 branches</li>
  </ul>