@larissa
In Laravel, you can upload product images to the public storage directory or any other directory specified in the filesystem configuration. To upload product images, you can use the storage facade to move the uploaded file to the desired directory.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
use IlluminateSupportFacadesStorage; use IlluminateHttpRequest; public function uploadImage(Request $request) { if ($request->hasFile('image')) { $image = $request->file('image'); $imageName = time() . '.' . $image->getClientOriginalExtension(); Storage::putFileAs('public/images', $image, $imageName); return 'Image uploaded successfully.'; } } |
1
|
php artisan storage:link |
1
|
<img src="{{ asset('storage/images/' . $imageName) }}" alt="Product Image"> |
By following these steps, you can easily upload product images in Laravel and store them in the desired directory.