title: Generate csv file using laravel
body: <p>I searched in google to generate the csv file from laravel and i have found the following code:</p>
  
  <pre><code>  public function download(){
    $headers = [
      'Cache-Control'       =&gt; 'must-revalidate, post-check=0, pre-  check=0'
      ,   'Content-type'        =&gt; 'text/csv'
      ,   'Content-Disposition' =&gt; 'attachment; filename=galleries.csv'
      ,   'Expires'             =&gt; '0'
      ,   'Pragma'              =&gt; 'public'
     ];
  
  $list = User::all()-&gt;toArray();
  
  # add headers for each column in the CSV download
  array_unshift($list, array_keys($list[0]));
  
  $callback = function() use ($list) 
  {
      $FH = fopen('php://output', 'w');
      foreach ($list as $row) { 
          fputcsv($FH, $row);
      }
      fclose($FH);
   };
  
  return Response::stream($callback, 200, $headers);
  }
  </code></pre>
  
  <p>In the above code, i didn't understand </p>
  
  <pre><code>$callback = function() use ($list){...}
  </code></pre>
  
  <p>will someone please explain me?</p>