Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel5 Json get file contents

I'm using Laravel-5 right now and I've just created a JSON file called test(test.json). My question is:

  1. Where should I put my JSON file?
  2. How can I use file_get_contents and point to that one file I wanted?

This is what I've tried which is obviously wrong:

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

Thank you so much for helping!

like image 796
KMackinley Avatar asked Feb 13 '16 00:02

KMackinley


1 Answers

You can store 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);  
like image 182
Jilson Thomas Avatar answered Sep 24 '22 19:09

Jilson Thomas