I have my Laravel project that will save files (txt or csv) after making some computations.
I'm looking after a best practice on where to save these files. Maybe /resources/csv/...?
Second question how would it be the best way to reference this path from within classes? Setting up the abs path in .env file? Is there a laravel method that will return the path to resources?
/resources are not the best place, as this folder is used for source files and is usually stored in source code repository (e.g. git).
Files that application generates usually end up somewhere in /storage folder - just create a /storage/csv folder there.
You should never reference those files directly from your classes. Laravel's filesystems are what you need - you can read more about them here: http://laravel.com/docs/master/filesystem. They make operations on the files (like read, write, prepend, append, delete, move, get all files and many more...) much simpler.
Start with defining a filesystems in your config/filesystems.php
'disks' => [
'csv' => [
'driver' => 'local',
'root' => storage_path().'/csv',
],
],
Now you can read/write your csv files via Storage facade from anywhere in your code like that:
Storage::disk('csv')->put('file.csv', $content);
$content = Storage::disk('csv')->get('file.csv');
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments