public function deleteCV($code) { $cv = Cv::where('cv_code', $code)->first(); if ($cv->exists) { if ($cv->user_id != Auth::id()) { return Redirect::Back()->with('fail', 'You are not authorized to delete this CV'); } else { $cv_id = $cv->id; Cv::find($cv_id)->delete(); Education::where('cv_id', $cv_id)->delete(); Language::where('cv_id', $cv_id)->delete(); Nysc::where('cv_id', $cv_id)->delete(); Section::where('cv_id', $cv_id)->delete(); WorkExperience::where('cv_id', $cv_id)->delete(); return Redirect::Back()->with('success', 'CV is successfully deleted'); } } else { return Redirect::Back()->with('fail', 'You are not authorized to delete this CV'); } }