You can check if the user has a profile photo and if they do, delete it first before uploading the new image.
Someone has a similar question on the issues: https://github.com/cloudinary-labs/cloudinary-laravel/issues/67
You can do something like this (rough code):
Route::post('/upload', function (Request $request) {
if (auth()->user()->profile_photo_id) {
// Cloudinary::destroy('testing/jt5dlp6y4st3dc9u0nqk');
Cloudinary::destroy(auth()->user()->profile_photo_id);
auth()->user()->profile_photo_id = null;
auth()->user()->save();
}
$cloudinaryUpload = Cloudinary::upload(
$request->file('file_upload')->getRealPath(),
[ 'folder' => 'testing' ]
);
auth()->user()->profile_photo_id = $cloudinaryUpload->getPublicId();
auth()->user()->profile_photo = $cloudinaryUpload->getSecurePath();
auth()->user()->save();
return back();
});
So you would store profile_photo_id so you can easily delete it if needed and you would also store profile_photo for the full path to the image.