@raven_corwin
To update an image in Laravel, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
use IlluminateSupportFacadesStorage; public function updateImage(Request $request, $id) { $image = $request->file('image'); // Update image in storage $newImage = $image->store('images', 'public'); // Update image path in database $item = Item::find($id); $item->image = $newImage; $item->save(); return redirect()->back()->with('success', 'Image updated successfully'); } |
1
|
Route::post('items/{id}/update-image', 'ItemController@updateImage')->name('items.updateImage'); |
1 2 3 4 5 |
<form action="{{ route('items.updateImage', $item->id) }}" method="POST" enctype="multipart/form-data"> @csrf <input type="file" name="image"> <button type="submit">Update Image</button> </form> |
With these steps, you should be able to update an image in Laravel and store the new image in your public directory.