Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel File not found at path but it does exist

Getting the following error in console when attempting to get a files contents:

[League\Flysystem\FileNotFoundException] File not found at path: C:/wamp64/www/lion/resources/generate/json/Car.json

When I copy and paste that exact path in explorer it opens the json file fine.

Here is my code:

$this->json = json_encode(Storage::get(resource_path('generate/json/'.$this->argument('model').'.json')));
like image 461
kjdion84 Avatar asked Jun 26 '17 22:06

kjdion84


2 Answers

I figured it out.

Storage::get actually uses the path relative to the filesystem disk configuration, therefore the error message itself is misleading.

I've corrected the issue by simply using file_get_contents() instead.

like image 75
kjdion84 Avatar answered Sep 17 '22 06:09

kjdion84


As others pointed out Storage::get indeed uses the path relative to the filesystem disk configuration, by default the local driver is used (config/filesystems.php):

'local' => [
    'driver' => 'local',
    'root' => storage_path('app'),
],

So if you are using the local driver and your file resides at app/public/yourfile.ext for example then the call to Storage should be:

Storage::get('public/yourfile.ext');
like image 35
Gluten Avatar answered Sep 19 '22 06:09

Gluten