I have a function in my laravel site where i submit form data to a database and save the submitted image in the storage directory. The data is stored correctly in the database, but somehow the images wont load and i dont know what to do anymore since this has been bugging me for a couple of days now.
If someone can see and tell me what i did wrong, that would be great!
I've created a symlink using
php artisan link:storage
filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'storage/public',
'visibility' => 'public',
],
PostController.php with the store function:
public function store(Request $request)
{
request()->validate([
'title' => ['required', 'string', 'max:255',],
'thumbnail' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048|unique:posts',
'iframe' => ['required', 'string', 'max:255',],
]);
$image = $request->file('thumbnail');
$originalname = $image->getClientOriginalName();
Storage::disk('public')->put($originalname, file_get_contents($image));
Post::create([
'title' => $request['title'],
'thumbnail' => $originalname,
'iframe' => $request['iframe'],
]);
return redirect()->route('adminPost.index');
}
This is how i am trying to load the image:
<img width="100px" src="{{asset('storage/public/'.$post->thumbnail)}}">
This is where my image is saved This is the path in the browser