After successful image upload you can see your image in storage/app/public/[and_your_file_for_images], now you have to link app/public with just public file cuz image is uploaded to app/public but users can access only public file, not app/public. With this command: php artisan storage:link you will link this two files and now users can access images in app/public through just public file. After this step you have to display your image in blade, add this code: {{url('storage/'.$your_variable)}} Hope this helps 🤞
Hi Tony Through this tutorial I had some problems, as the image was not being deleted, the way I added the image in a non-public place and to show the image in the view, so here's how I improved it, in case anyone has the same problem. In view: in Controller Post update: $validate = $request->validate([ 'title' => ['required', 'min:3', 'max:255'], 'content' => ['required', 'min:10', 'max:255'], 'thumbnail' => ['nullable', 'image', 'mimes:jpg,png,jpeg,gif', 'max:2048'] ]); if ($request->hasFile('thumbnail')) { if (Storage::exists($post->thumbnail)) { Storage::delete($post->thumbnail); } $validate['thumbnail'] = $request->file('thumbnail')->store('public/thumbnails'); } $post->update($validate); store: $validate = $request->validate([ 'title' => ['required', 'min:3', 'max:255'], 'content' => ['required', 'min:10', 'max:255'], 'thumbnail' => ['nullable', 'image', 'mimes:jpg,png,jpeg,gif', 'max:2048'] ]); $validate['thumbnail'] = $request->file('thumbnail')->store('public/thumbnails'); auth()->user()->posts()->create($validate); delete: Storage::delete($post->thumbnail); $post->delete();
28 File Upload - Laravel 11 tutorial for beginners.
thanks alot man
Great work Tony! Can you tell us which font is this that you are using?
It would be interesting to show the management of multiple doc and pdf files
How uploaded file laravel with nuxt3
hi! what pluggin do you have for those snippets/help when you write laravel code?
You did not say how to display the same uploaded file
After successful image upload you can see your image in storage/app/public/[and_your_file_for_images], now you have to link app/public with just public file cuz image is uploaded to app/public but users can access only public file, not app/public. With this command: php artisan storage:link you will link this two files and now users can access images in app/public through just public file. After this step you have to display your image in blade, add this code: {{url('storage/'.$your_variable)}}
Hope this helps 🤞
Please use normal font
Hi Tony
Through this tutorial I had some problems, as the image was not being deleted, the way I added the image in a non-public place and to show the image in the view, so here's how I improved it, in case anyone has the same problem.
In view:
in Controller Post
update:
$validate = $request->validate([
'title' => ['required', 'min:3', 'max:255'],
'content' => ['required', 'min:10', 'max:255'],
'thumbnail' => ['nullable', 'image', 'mimes:jpg,png,jpeg,gif', 'max:2048']
]);
if ($request->hasFile('thumbnail')) {
if (Storage::exists($post->thumbnail)) {
Storage::delete($post->thumbnail);
}
$validate['thumbnail'] = $request->file('thumbnail')->store('public/thumbnails');
}
$post->update($validate);
store:
$validate = $request->validate([
'title' => ['required', 'min:3', 'max:255'],
'content' => ['required', 'min:10', 'max:255'],
'thumbnail' => ['nullable', 'image', 'mimes:jpg,png,jpeg,gif', 'max:2048']
]);
$validate['thumbnail'] = $request->file('thumbnail')->store('public/thumbnails');
auth()->user()->posts()->create($validate);
delete:
Storage::delete($post->thumbnail);
$post->delete();