Reputation: 2848
Route::get('marquee', function(){
echo File::get('\storage\app\marquee.json');
});
I have a json file place inside storage/app
My question is how can I read this content from controller or route?
Upvotes: 23
Views: 130201
Reputation: 163968
Using Storage
facade:
Storage::disk('local')->get('marquee.json');
The old way, using File
facade (deprecated for Laravel 7):
File::get(storage_path('app/marquee.json'));
Upvotes: 53
Reputation: 2102
From external source use Http requests, documentation here, eg:
$response = Http::get('http://test.com');
Upvotes: 3
Reputation: 2156
You can store files in your storage folder in Laravel:
$path = storage_path() . "/json/${filename}.json";
$json = json_decode(file_get_contents($path), true);
Upvotes: 2
Reputation: 682
You can go with the absolute path
\Illuminate\Support\Facades\File::get(base_path() . '/storage/app/marquee.json');
Upvotes: 7
Reputation: 2855
You can use storage_path() function for locate the storage folder and then join app folder name like that:
$path = storage_path() . "/app/marquee.json";
echo File::get($path);
Upvotes: 5
Reputation: 116
Try this code
File::get(storage_path('app\marquee.json'));
Upvotes: 6