First things first, I upload an image to a Storage:: in the controller like this:
$ranker = Ranker::create([ ... ]);
if ($request->file('file')) {
$filename = Storage::put('ranker', $request->file('file');
$ranker->image_url = $filename;
$ranker->save();
}
So this is working, in the database I got a url in the proper field, something like: ranker/v14rzsqJjlJIEYG2Cd22l1MLxeNPd0hGI0rvLjrf.png. If I go to \app\Storage\app\ranker I see the file, and it is correctly uploaded.
Now, when I want to render the file I do something simple as:
<img src="{{ Storage::url($ranker->image_url) }}" ... >
The src correctly says: /storage/ranker/v14rzsqJjlJIEYG2Cd22l1MLxeNPd0hGI0rvLjrf.png but displays nothing. If I go to http://server/storage/ranker/v14rzsqJjlJIEYG2Cd22l1MLxeNPd0hGI0rvLjrf.png I got a 404
Any ideas?
>Solution :
The Storage folder is not a publicly accessible folder, so you either need to save the image in the public directory or link the storage public folder to the public folder by running the following artisan command in the cli.
php artisan storage:link
Then when saving you need to add it to the public folder by choosing the public disk as default or selecting the disk like this
Storage::disk('public')->put('ranker', $request->file('file'));
And then output:-
{{ Storage::disk('public')->url($ranker->image_url) }}