I have an image within the public/badges directory called 1.png - I am trying to use the Storage library in laravel but keep getting the following error even though the file does exist at that location:
// Error
FileNotFoundException in Filesystem.php line 381:
File not found at path: Users/gk/Sites/mysite/public/badges/1.png
// Code
$filePath = 'badges/1.png';
$path = public_path()."/".$filePath
Storage::disk('local')->get($path);
dd($contents);
Form Laravel 5.2 documentation:
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory.
So You are looking for file in: storage/app/Users/gk/Sites/mysite/public/badges/1.png
Error is quite confusing.
[Update]
Add to config/filesystems.php
'disks' => [
//...
'local_public' => [
'driver' => 'local',
'root' => public_path(),
],
//...
],
then
$filePath = 'badges/1.png';
$content = Storage::disk('local_public')->get($filePath);
dd($content);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With