doobz's avatar
Level 1

Load CSV file into Controller to prase using a .env variable

Ok, so I have a .env variable CSV_FILE=~/sites/computer-availability/storage/app/WAV_SUM.csv

I want to load it into my controller so that I can parse it into an array. I tried env("app.CSV_FILE"); but that just gives me a string. Not what I'm wanting.

How could I go about loading the data from the CSV file using the .env variable?

0 likes
4 replies
macedorjd's avatar

Try this

$csv = File::get(env("app.CSV_FILE));
dd($csv);
doobz's avatar
Level 1

@macedorjd FatalThrowableError in Controller.php line 14: Class 'App\Http\Controllers\File' not found

Cronix's avatar

@doobz You need to import File, or use the FQN.

use File;

or $csv = \File::get(...)

Please or to participate in this conversation.