Skip to content

Instantly share code, notes, and snippets.

@Nemachtilli
Created April 26, 2022 17:16
Show Gist options
  • Select an option

  • Save Nemachtilli/2de0a649e4894e107c1820325a67db2b to your computer and use it in GitHub Desktop.

Select an option

Save Nemachtilli/2de0a649e4894e107c1820325a67db2b to your computer and use it in GitHub Desktop.
public function destroyCourse(Course $course)
{
try {
if (request()->ajax()) {
if ($course->file) {
Uploader::removeFile("courses", $course->file);
}
$units = Unit::where('course_id', $course->id)->get();
foreach ($units as $unit) {
if (Storage::disk('public')->exists('units/' . $unit->file)) {
Storage::delete('units/' . $unit->file);
}
}
$course->delete();
session()->flash("message", ["success", __("El curso con el :id ha sido eliminado correctamente", [
"id" => $course->id
])]);
return back();
} else {
abort(401);
}
} catch (\Exception $exception) {
session()->flash("message", ["danger", $exception->getMessage()]);
return back();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment