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 @@
Basics
+ + {{-- Academic Program --}}
- +
+ @@ -70,9 +79,11 @@
{{ $message }}
@enderror
+ + {{-- Course Code --}}
- +
@@ -81,9 +92,11 @@ {{ $message }} @enderror
+ + {{-- Course Name --}}
- +
@@ -94,11 +107,12 @@
+ {{-- Course Type --}}
- +
- @foreach (App\Domains\AcademicProgram\Course\Models\Course::getTypes() as $key => $value) @@ -108,9 +122,11 @@
{{ $message }}
@enderror
+ + {{-- Credits --}}
- +
@@ -119,6 +135,22 @@ {{ $message }} @enderror
+ + {{-- Teaching Methods --}} +
+
+ +
+
+ +
+ @error('teaching_methods') +
{{ $message }}
+ @enderror +
+ + {{-- FAQ Page --}}
@@ -131,6 +163,8 @@
{{ $message }}
@enderror
+ + {{-- Content --}}
@@ -187,7 +221,7 @@
- {{-- ILO --}} + {{-- ILOs --}} @foreach ($ilos as $key => $value)
@livewire('backend.item-adder', ['type' => $key, 'items' => $ilos[$key]], key("ilos-$key-adder")) @@ -203,14 +237,15 @@
Modules & References
+ {{-- Modules --}}
+ {{-- References --}}
@livewire('backend.item-adder', ['type' => 'references', 'items' => $references], key('references-adder'))
-
diff --git a/resources/views/livewire/backend/edit-courses.blade.php b/resources/views/livewire/backend/edit-courses.blade.php index ddf4758..e0a6ca5 100644 --- a/resources/views/livewire/backend/edit-courses.blade.php +++ b/resources/views/livewire/backend/edit-courses.blade.php @@ -23,10 +23,12 @@
Basics
+ + {{-- Academic Program --}}
@@ -56,9 +60,11 @@
{{ $message }}
@enderror
+ + {{-- Semester --}}
- +
@@ -82,9 +90,11 @@ {{ $message }} @enderror
+ + {{-- Course Name --}}
- +
@@ -96,9 +106,10 @@
+ {{-- Course Type --}}
- +
@@ -121,6 +134,22 @@ {{ $message }} @enderror
+ + {{-- Teaching Methods --}} +
+
+ +
+
+ +
+ @error('teaching_methods') +
{{ $message }}
+ @enderror +
+ + {{-- FAQ Page --}}
@@ -133,6 +162,8 @@
{{ $message }}
@enderror
+ + {{-- Content --}}
@@ -162,7 +193,6 @@
- {{-- objectives --}}
{!! Form::textarea('objectives', '', [ @@ -192,7 +222,7 @@
- {{-- ILO --}} + {{-- ILOs --}} @foreach ($ilos as $key => $value)
@livewire('backend.item-adder', ['type' => $key, 'items' => $ilos[$key]], key("ilos-$key-adder")) @@ -208,9 +238,15 @@
Modules & References
- -
- @livewire('backend.item-adder', ['type' => 'references', 'items' => $references], key('references-adder')) + {{-- Modules --}} +
+ +
+ + {{-- References --}} +
+ @livewire('backend.item-adder', ['type' => 'references', 'items' => $references], key('references-adder')) +