title: Saving to a csv file
body: <p>I'm trying to create a function where it will take a table and then copy that and add it to csv file.
  The issue I'm having is that it isn't saving to the csv.
  I'm using docker with my laravel.</p>
  <p>Here is my code</p>
  <pre><code>$temp = strtolower('project_'.Str::random(8));
  $query = $project-&gt;queries-&gt;query;
  
  $statement = &quot;CREATE TABLE $temp AS $query&quot;;
  DB::connection('data')-&gt;statement($statement);
  
  $csvFile = storage_path(&quot;app/project/project_report.csv&quot;);
  $path = storage_path(&quot;app/project/&quot;);
  
  $file = fopen($csvFile, 'w+');
  $process = new Process([&quot;psql -h &quot;.env('DB_HOST').&quot; -d $temp -c&quot;, &quot;\copy $temp to $csvFile delimiter ',' csv header&quot;], $path);
  $process-&gt;run();
  fclose($file);
  </code></pre>