KMackinley
KMackinley

Reputation: 457

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!

Upvotes: 38

Views: 57829

Answers (1)

Jilson Thomas
Jilson Thomas

Reputation: 7303

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); 

Upvotes: 85

Related Questions