diff --git a/app/Http/Livewire/Backend/CreateCourses.php b/app/Http/Livewire/Backend/CreateCourses.php index aa59e11..151786f 100644 --- a/app/Http/Livewire/Backend/CreateCourses.php +++ b/app/Http/Livewire/Backend/CreateCourses.php @@ -33,6 +33,7 @@ class CreateCourses extends Component public $time_allocation; public $module_time_allocation; public $marks_allocation; + public $teaching_methods; //2nd form step public $objectives; @@ -53,6 +54,7 @@ public function rules() 'code' => 'required|string|unique:courses,code', 'name' => 'required|string|max:255', 'credits' => 'required|integer|min:1|max:18', + 'teaching_methods' => 'nullable|string', 'faq_page' => 'nullable|url', 'content' => 'nullable|string', 'time_allocation.lecture' => 'nullable|integer|min:0', @@ -105,6 +107,7 @@ protected function validateCurrentStep() 'code' => 'required|string|unique:courses,code', 'name' => 'required|string|max:255', 'credits' => 'required|integer|min:1|max:18', + 'teaching_methods' => 'nullable|string', 'faq_page' => 'nullable|url', 'content' => 'nullable|string', ]; @@ -269,6 +272,7 @@ protected function storeCourse() 'code' => $this->code, 'name' => $this->name, 'credits' => (int)$this->credits, + 'teaching_methods' => $this->teaching_methods, 'faq_page' => $this->faq_page, 'content' => $this->content, 'time_allocation' => json_encode($this->time_allocation), @@ -319,6 +323,7 @@ protected function resetForm() $this->code = ''; $this->name = ''; $this->credits = 0; + $this->teaching_methods = ''; $this->faq_page = ''; $this->content = ''; $this->time_allocation = Course::getTimeAllocation(); diff --git a/app/Http/Livewire/Backend/EditCourses.php b/app/Http/Livewire/Backend/EditCourses.php index 0a4838a..21a3389 100644 --- a/app/Http/Livewire/Backend/EditCourses.php +++ b/app/Http/Livewire/Backend/EditCourses.php @@ -31,6 +31,7 @@ class EditCourses extends Component public $time_allocation; public $module_time_allocation; public $marks_allocation; + public $teaching_methods; // 2nd form step public $objectives; @@ -47,7 +48,6 @@ class EditCourses extends Component public function rules() { - $validationRules = [ 'academicProgram' => 'required|string', 'semester' => 'required|int', @@ -56,6 +56,7 @@ public function rules() 'code' => 'required|string', 'name' => 'required|string|max:255', 'credits' => 'required|integer|min:1|max:18', + 'teaching_methods' => 'nullable|string', 'faq_page' => 'nullable|url', 'content' => 'nullable|string', 'modules' => 'nullable|array', @@ -169,6 +170,7 @@ public function mount(Course $course) $this->code = $course->code; $this->name = $course->name; $this->credits = $course->credits; + $this->teaching_methods = $course->teaching_methods; $this->faq_page = $course->faq_page; $this->content = $course->content; $this->time_allocation = array_merge(Course::getTimeAllocation(), json_decode($course->time_allocation, true)); @@ -186,6 +188,8 @@ public function mount(Course $course) 'time_allocation' => array_merge(Course::getTimeAllocation(), json_decode($module->time_allocation, true)) ]; })->toArray(); + $this->prerequisites = $course->prerequisites; + $this->prerequisites = $course->prerequisites->pluck('id')->toArray(); // Update semesters list based on academic program and version @@ -228,9 +232,15 @@ public function previous() public function update() { - $this->validateCurrentStep(); - $this->updateCourse(); - return redirect()->route('dashboard.courses.index')->with('Success', 'Course updated successfully.'); + try { + $this->validateCurrentStep(); + $this->updateCourse(); + return redirect()->route('dashboard.courses.index')->with('Success', 'Course updated successfully.'); + } catch (\Exception $e) { + \Log::error("Error in update method: " . $e->getMessage()); + session()->flash('error', 'There was an error updating the course: ' . $e->getMessage()); + } + $this->resetForm(); } public function updatedAcademicProgram() @@ -290,6 +300,7 @@ protected function updateCourse() 'code' => $this->code, 'name' => $this->name, 'credits' => (int)$this->credits, + 'teaching_methods' => $this->teaching_methods, 'faq_page' => $this->faq_page, 'content' => $this->content, 'time_allocation' => json_encode($this->time_allocation), @@ -305,7 +316,7 @@ protected function updateCourse() if (!empty($this->modules)) { foreach ($this->modules as $module) { - $createdModule = CourseModule::create([ + CourseModule::create([ 'course_id' => $course->id, 'topic' => $module['name'], 'description' => $module['description'], @@ -315,6 +326,7 @@ protected function updateCourse() ]); } } + // Sync prerequisites if (!empty($this->prerequisites)) { $course->prerequisites()->sync(collect($this->prerequisites)->pluck('id')->toArray()); @@ -340,6 +352,7 @@ protected function resetForm() $this->code = ''; $this->name = ''; $this->credits = null; + $this->teaching_methods = ''; $this->faq_page = ''; $this->content = ''; $this->time_allocation = Course::getTimeAllocation(); diff --git a/database/factories/CourseFactory.php b/database/factories/CourseFactory.php index 9ad2151..732d95a 100644 --- a/database/factories/CourseFactory.php +++ b/database/factories/CourseFactory.php @@ -36,6 +36,8 @@ public function definition() 'name' => $this->faker->sentence(3), 'credits' => $this->faker->numberBetween(1, 6), 'type' => $this->faker->randomElement(array_keys(Course::getTypes())), + 'teaching_methods' => $this->faker->sentence(3), + 'faq_page' => $this->faker->url, 'content' => $this->faker->paragraph(), 'objectives' => json_encode([$this->faker->sentence(), $this->faker->sentence()]), 'time_allocation' => json_encode(['lectures' => $this->faker->numberBetween(10, 50), 'practicals' => $this->faker->numberBetween(5, 20)]), @@ -48,4 +50,4 @@ public function definition() 'updated_at' => now(), ]; } -} +} \ No newline at end of file diff --git a/database/migrations/2024_10_10_103420_add-field-teaching-methods.php b/database/migrations/2024_10_10_103420_add-field-teaching-methods.php new file mode 100644 index 0000000..b8b7e56 --- /dev/null +++ b/database/migrations/2024_10_10_103420_add-field-teaching-methods.php @@ -0,0 +1,32 @@ +text('teaching_methods')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('courses', function (Blueprint $table) { + $table->dropColumn('teaching_methods'); + }); + } +} diff --git a/resources/views/livewire/backend/create-courses.blade.php b/resources/views/livewire/backend/create-courses.blade.php index 9c8f2b1..c59b0d3 100644 --- a/resources/views/livewire/backend/create-courses.blade.php +++ b/resources/views/livewire/backend/create-courses.blade.php @@ -23,11 +23,15 @@