Laravel5 Json get file contents

I am using Laravel-5right now and I just created a file JSONcalled test (test.json). My question is:

  • Where should I put my JSON file?
  • How can I use file_get_contents and point to the file that I need?

Here is what I tried, which is clearly wrong:

$string = file_get_contents("../json/test.json");   
$json_file = json_decode($string, true);

Thank you so much for your help!

+4
source share
1 answer

You can save it in your storage folder in Laravel:

$path = storage_path() . "/json/${filename}.json"; // ie: /var/www/laravel/app/storage/json/filename.json

$json = json_decode(file_get_contents($path), true); 
+11
source

Source: https://habr.com/ru/post/1628593/


All Articles