public function deleteProject($id) { $projectsTable = new \App\Model\Projects(); $projects = $projectsTable->where("id", '=', $id)->first(); $image = $projects->image_location; $imageLoc = "uploads/projects/" . $image; $projectImage = $projectsTable->deleteData($id); if ($projectImage) { if ($image != '') { if (File::exists($imageLoc)) { File::delete($imageLoc); } } $message['message'] = 'Successfully Deleted'; return Redirect::to('admin/project-list/')->withErrors($message); } else { $message['message'] = 'Cannot delete file'; return Redirect::to('admin/project-list/')->withErrors($message); } }