I require to delete the uploaded image from the image folder. In fact, my image folder does not exist in the public directory. Basically, it falls under the project root directory, for example (projectfolder->images). Moreover, my JavaScript and CSS files also exist in the root directory. That's why I am using the base_path() function and returning the true file path, but an image is not deleting.
public function deleteUploadGallery(Request $request)
{
$name = $request->name;
$authUser = Auth::User()->toArray();
$match = ['user_id' => $authUser['id'],
'image_type' => 'gallery', 'image_name' => $name];
$originalPath = base_path('images/' . $request->name);
$thumbnailPath = base_path('images/thumbnail/' . $request->name);
if (File::exists($originalPath)) {
@unlink($originalPath);
}
if (file_exists($thumbnailPath)) {
@unlink($thumbnailPath);
}
$userMedia = UsersInfoMedia::where($match)->first();
$userMedia->delete();
return response()->json(['success' => 'Image Deleted Successfully.']);
}