@shyann
To update an image file in Laravel, follow these steps:
1
|
use IlluminateSupportFacadesStorage; |
1
|
$existingData = YourModel::findOrFail($id); |
1 2 3 4 5 6 7 8 9 10 |
if ($request->hasFile('image')) { // Delete the existing image file if it exists Storage::delete($existingData->image); // Store the new image file $path = $request->file('image')->store('images'); // Update the image file path in the database $existingData->image = $path; } |
1
|
$existingData->save(); |
Make sure to replace "YourModel" with the name of your model class and "image" with the name of the column in your database table that stores the image file path.
Remember to handle form validation and file validation according to your needs.