webfuelcode's avatar

Delete old file if new file is selected

I have tried this but this does not working. Laravel 11 is not passing the user variable on editing (breeze).

Just wanna remove the old image when user want new image.

0 likes
4 replies
manishchauhan's avatar

try using Storage

if ($oldImage && Storage::exists($oldImagePath)) { Storage::delete($oldImagePath); }

Snapey's avatar

nobody can help with "does not working"

1 like
experimentor's avatar

@webfuelcode The entire logic of replacing user's image lies within this "if" block condition

if ($request->hasFile('image'))

Maybe the frontend form / ajax request is not sending image in the request. Please check that first.

If that part is fine, you can debug by adding Log::info at various points in your code.

1 like

Please or to participate in this conversation.