Read a .csv file into an array in Laravel
<p>I have stored a .csv file in this directory in Laravel 5 :</p>

<p>/storage/app/data.csv</p>

<p>Inside of this function I am trying to read the contents of this file and extract a few columns from it, like name and city to an array, sample code:</p>

<pre><code>use Illuminate\Support\Facades\Storage;

public function get_data() {

 $file_n = Storage::url('data.csv');
 $file = fopen($file_n, "r");
 $all_data = array();
 while ( ($data = fgetcsv($file, 200, ",")) !==FALSE {

     $name = $data[0];
     $city = $data[1];
     $all_data = $name. " ".$city;

     array_push($array, $all_data);
  }
  fclose($file);
}
</code></pre>

<p>I am getting an ErrorException in Controller:</p>

<pre><code>fopen(/storage/data.csv): failed to open stream: No such file or directory
</code></pre>

<p>But the file is there. Is there a better way to do this instead?</p>

<p>Thanks for looking!</p>