rakibtg rakibtg - 8 days ago 6
PHP Question

Laravel 5.3 storage cant find uploaded file

I am using laravel Filesystem to store images, the image will be uploaded inside the default storage, example:


/home/user/Projects/mywebapp/storage/app/images/posts/1/e392e17926559e7cc4e7934f.png


I didnt change the
config/filesystem.php
and here is my controller method to upload an image,

public function storeImage( Request $request ) {
$image = $request->file( 'image' )->store( 'images/posts/'.Auth::user()->id );
echo Storage::url( $image ); // <- print the url of the uploaded image
}


This would print the image url like this,


http://localhost:8000/storage/images/posts/1/e392e17c6a8d7926559e8e7cc4e7934f.png


But the image file is not accessable from the browser!
I dont want to use php to dynamically fetch the images, i just wanted to make them publicly accessable over http. How to display the image?

Answer

you just have to make a change in config\filesystems.php form

'default' => local,

to 'default' => public,

then in console run php artisan storage:link

then try the above code and it will work