Created
April 26, 2022 17:16
-
-
Save Nemachtilli/2de0a649e4894e107c1820325a67db2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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