Your $img->path should save to public, because storage is not accessible from the web root (public)
$img->path = '/images/'.$filename;
I'm building a CMS for a small project so I can learn how to use Laravel properly. I am writing a system to upload and show some images, however I am confused about the correct way to access them once uploaded.
public function storeImage(Request $request)
{
$request->file('image')->store('public/images');
$filename = md5_file($request->file('image')) . '.' . $request->file('image')->extension();
$img = new Image;
$img->path = 'storage/images/'.$filename;
$img->save();
return back();
}
This works fine, and I have symlinked storage as suggested, however if I use the $filename variable from the database I get a 404. What is the correct path to generate to insert as an inline image src attribute here?
The image tag looks like this:
<img src="storage/images/89cdd31f2e0eeacceff96c2a0abb252f.jpeg" alt="pig">
I can see that in my public folder there is a little symlinked storage folder in PHPStorm.
Please or to participate in this conversation.