Where to save files in Laravel 5 folder structure?

koalaok

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?

jedrzej.kurylo

/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.

edited at
0

Comments

0 comments
Login to comment

Related

Where Laravel Storage save the files?

Objective c: Where to save the files in folder?

Where to store JSON file inside Laravel folder structure

save unzipped files to a folder

save image in public folder instead storage laravel 5

Create archive file with original the file structure, so that un-archive will extract those files/folder to exactly where it was

Save stashed files into another folder

Save downloaded files in folder (Python)

Where does CodeDom save generated .cs files? Can we change this location to a Different Folder

Laravel 5 Models Folder

Laravel 5 Views Structure

Save .xlsx files in a folder to .csv files

Move files and folder without removing folder structure of source folder

Where to save files in ftp host

Where to start in Phonegap 3 folder structure

Move files to new folder structure using Terminal

zipping files in python without folder structure

Copy folder structure and only files name

Gulp: preserving folder structure on destination for individual files

Windows batch script to copy files with folder structure

Configuring Webpack to required folder structure for build files

Finding files and copy with folder structure intact

Powershell copy only selected files with folder structure

Terraform Folder Structure - Modules vs Files

Copy files using python with complete folder structure

rsync not copying files (just folder structure)

Sass - Complex folder structure with a lot of css files

Move files from one folder structure to another

upload more files to a folder with laravel