title: Export whole table to CSV using laravel
body: <p>I am new to laravel and having a tough time figuring out a way to export one table to csv.
  I have tried the following code in the controller class, but it gives me an error:</p>
  
  <pre><code>    public function get_export()
  {
      $table = Cpmreport::all();
      $file = fopen('file.csv', 'w');
      foreach ($table as $row) {
          fputcsv($file, $row);
      }
      fclose($file);
      return Redirect::to('consolidated');
  }
  </code></pre>
  
  <p>Model Class for Cpmreport:</p>
  
  <pre><code>    class Cpmreport extends Eloquent
      {
        public static $table='cpm_report';
      }
  </code></pre>
  
  <p>The error :</p>
  
  <pre><code>    Message:
  
      fputcsv() expects parameter 2 to be array, object given
  
      Location:
  
      C:\xampp\htdocs\cpm_report\application\controllers\cpmreports.php on line 195
  </code></pre>
  
  <p>Any help would be appreciated.</p>