Rodrigo Calix Rodrigo Calix - 5 months ago 82
JSON Question

How to create a text file and a JSON with laravel 4 framework?

Hello!, the question might be simple, but i couldn't find the answer.



i want to create a .txt file with laravel 4 and upload it to my server like PHP does, and also
i need to create a JSON file with laravel 4 and upload it to my server.

Thanks for your help!

Answer

To use the filesystem of Laravel, you should access it through the File Facade.

Create a new file:

//Usage
File::put($path,$contents);
//Example
File::put('web/text/mytextdocument.txt','John Doe');

Delete a file:

//Usage
File::delete(string|array $paths)
//Example
File::deleted('web/text/mytextdocument.txt');

The complete documentation on all available methods is found here: http://laravel.com/api/4.1/Illuminate/Filesystem/Filesystem.html