How to load json file in Laravel Controller?

I have a JSON file that I would like to upload to a controller in Laravel so that I can use the data in my application.

The path to the files is / storage / app / calendar_Ids.json.

What is the right way to do this?

+4
source share
3 answers

Here it should help you sort out.

use Storage;

$json = Storage::disk('local')->get('calendar_Ids.json');
$json = json_decode($json, true);
+7
source

try it

$path = '/storage/app/calendar_Ids.json';
$content = json_decode(file_get_contents($path), true);`

Then just dd($content);to see if it works.

+2
source

You can also try:

$json = storage_path('folder/filename.json');
0
source

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


All Articles