Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel get file content

Tags:

php

laravel

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?

like image 697
Benjamin W Avatar asked Mar 29 '17 11:03

Benjamin W


People also ask

How do I get files in Laravel?

If you have file object from request then you can simply get by laravel function. $extension = $request->file->extension(); dd($extension); If you have file object from request then you can simply get by laravel function.

How can I get storage path in Laravel 8?

You can use the storage_path(); function to get storage folder path.


2 Answers

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'));
like image 170
Alexey Mezenin Avatar answered Oct 08 '22 21:10

Alexey Mezenin


Try this code

File::get(storage_path('app\marquee.json'));
like image 31
Vladimir Makarov Avatar answered Oct 08 '22 20:10

Vladimir Makarov