Laravel data delete with multiple image without public path
public function destroyProjects($id){
$project = Project::findOrFail($id);
// Extract the image paths from the URLs
$img_one_path = parse_url($project->img_one, PHP_URL_PATH);
$img_two_path = parse_url($project->img_two, PHP_URL_PATH);
// Convert the relative paths to absolute paths
$img_one_path = public_path($img_one_path);
$img_two_path = public_path($img_two_path);
// Delete the images from the file system
if (File::exists($img_one_path)) {
File::delete($img_one_path);
}
if (File::exists($img_two_path)) {
File::delete($img_two_path);
}
// Delete the project record from the database
$project->delete();
$notification = array(
'message' => 'Project Delected!',
'alert-type' => 'success'
);
return redirect()->back()->with($notification);
} // end mehtod
No comments