diff --git a/app/Http/Controllers/Backend/Courses/MaterialController.php b/app/Http/Controllers/Backend/Courses/MaterialController.php index bb37974..35ea06d 100644 --- a/app/Http/Controllers/Backend/Courses/MaterialController.php +++ b/app/Http/Controllers/Backend/Courses/MaterialController.php @@ -38,7 +38,7 @@ public function store(AddNewRequest $request) try { $material = new Material; $material->title = $request->materialTitle; - $material->course_id = $request->courseId; + $material->lesson_id = $request->lessonId; $material->type = $request->materialType; $material->content = $request->content; $material->content_url = $request->contentURL; @@ -88,7 +88,7 @@ public function update(UpdateRequest $request, $id) try { $material = Material::findOrFail(encryptor('decrypt', $id)); $material->title = $request->materialTitle; - $material->course_id = $request->courseId; + $material->lesson_id = $request->lessonId; $material->type = $request->materialType; $material->content_url = $request->contentURL; diff --git a/app/Http/Controllers/LessonController.php b/app/Http/Controllers/LessonController.php new file mode 100644 index 0000000..c81479d --- /dev/null +++ b/app/Http/Controllers/LessonController.php @@ -0,0 +1,113 @@ +title = $request->lessonTitle; + $lesson->course_id = $request->courseId; + + if ($lesson->save()) { + $this->notice::success('Data Saved'); + return redirect()->route('lesson.index'); + } else { + $this->notice::error('Please try again'); + return redirect()->back()->withInput(); + } + } catch (Exception $e) { + // dd($e); + $this->notice::error('Please try again'); + return redirect()->back()->withInput(); + } + } + + /** + * Display the specified resource. + */ + public function show(Lesson $lesson) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Lesson $lesson) + { + $course = Course::get(); + $lesson = Lesson::findOrFail(encryptor('decrypt', $id)); + return view('backend.course.lesson.edit', compact('course', 'lesson')); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, Lesson $lesson) + { + try { + $lesson = Lesson::findOrFail(encryptor('decrypt', $id)); + $lesson->title = $request->lessonTitle; + $lesson->lesson_id = $request->lessonId; + $lesson->type = $request->materialType; + $lesson->content_url = $request->contentURL; + + if ($request->hasFile('content')) { + $contentName = rand(111, 999) . time() . '.' . $request->content->extension(); + $request->content->move(public_path('uploads/courses/contents'), $contentName); + $lesson->content = $contentName; + } + if ($lesson->save()) { + $this->notice::success('Data Saved'); + return redirect()->route('lesson.index'); + } else { + $this->notice::error('Please try again'); + return redirect()->back()->withInput(); + } + } catch (Exception $e) { + // dd($e); + $this->notice::error('Please try again'); + return redirect()->back()->withInput(); + } + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Lesson $lesson) + { + $data = Lesson::findOrFail(encryptor('decrypt', $id)); + if ($data->delete()) { + $this->notice::error('Data Deleted!'); + return redirect()->back(); + } + } +} diff --git a/app/Models/Lesson.php b/app/Models/Lesson.php new file mode 100644 index 0000000..ed1165d --- /dev/null +++ b/app/Models/Lesson.php @@ -0,0 +1,11 @@ +id(); + $table->string('title', 255)->nullable(false); + $table->unsignedBigInteger('course_id')->index(); + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('course_id')->references('id')->on('courses')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('lessons'); + } +}; diff --git a/database/migrations/2023_11_26_153620_create_materials_table.php b/database/migrations/2023_11_26_153620_create_materials_table.php index c937dfd..d5789be 100644 --- a/database/migrations/2023_11_26_153620_create_materials_table.php +++ b/database/migrations/2023_11_26_153620_create_materials_table.php @@ -13,7 +13,7 @@ public function up(): void { Schema::create('materials', function (Blueprint $table) { $table->id(); - $table->unsignedBigInteger('course_id')->index(); + $table->unsignedBigInteger('lesson_id')->index(); $table->string('title', 255)->nullable(false); $table->enum('type', ['video', 'document', 'quiz'])->nullable(false); $table->string('content')->nullable(); @@ -21,7 +21,7 @@ public function up(): void $table->timestamps(); $table->softDeletes(); - $table->foreign('course_id')->references('id')->on('courses')->onDelete('cascade'); + $table->foreign('lesson_id')->references('id')->on('lessons')->onDelete('cascade'); }); } diff --git a/resources/views/backend/course/lesson/create.blade.php b/resources/views/backend/course/lesson/create.blade.php new file mode 100644 index 0000000..a3b8aed --- /dev/null +++ b/resources/views/backend/course/lesson/create.blade.php @@ -0,0 +1,123 @@ +@extends('backend.layouts.app') +@section('title', 'Add Course Material') + +@push('styles') + + + +@endpush + +@section('content') + +
+ +
+ +
+
+
+

Add Course Material

+
+
+ +
+ +
+
+
+
+
Basic Info
+
+
+
+ @csrf +
+
+
+ + +
+ @if($errors->has('materialTitle')) + {{ $errors->first('materialTitle') }} + @endif +
+
+
+ + +
+ @if($errors->has('courseId')) + {{ $errors->first('courseId') }} + @endif +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+ @if($errors->has('contentURL')) + {{ $errors->first('contentURL') }} + @endif +
+
+ + +
+
+
+
+
+
+
+ +
+
+ +@endsection + +@push('scripts') + + + + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/course/lesson/edit.blade.php b/resources/views/backend/course/lesson/edit.blade.php new file mode 100644 index 0000000..5a4bfe0 --- /dev/null +++ b/resources/views/backend/course/lesson/edit.blade.php @@ -0,0 +1,130 @@ +@extends('backend.layouts.app') +@section('title', 'Edit Course Material Material') + +@push('styles') + + + +@endpush + +@section('content') + +
+ +
+ +
+
+
+

Edit Course Material

+
+
+ +
+ +
+
+
+
+
Basic Info
+
+
+
+ @csrf + @method('PATCH') + +
+
+
+ + +
+ @if($errors->has('materialTitle')) + {{ $errors->first('materialTitle') }} + @endif +
+
+
+ + +
+ @if($errors->has('courseId')) + {{ $errors->first('courseId') }} + @endif +
+
+
+ + +
+ @if($errors->has('materialType')) + {{ $errors->first('materialType') }} + @endif +
+
+
+ + +
+
+
+
+ + +
+ @if($errors->has('contentURL')) + {{ $errors->first('contentURL') }} + @endif +
+
+ + +
+
+
+
+
+
+
+ +
+
+ +@endsection + +@push('scripts') + + + + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/course/lesson/index.blade.php b/resources/views/backend/course/lesson/index.blade.php new file mode 100644 index 0000000..5914420 --- /dev/null +++ b/resources/views/backend/course/lesson/index.blade.php @@ -0,0 +1,119 @@ +@extends('backend.layouts.app') +@section('title', 'Course Material List') + +@push('styles') + + +@endpush + +@section('content') + +
+ +
+ +
+
+
+

Course Material List

+
+
+ +
+ +
+ +
+
+
+
+
+

All Course Materials List

+ + Add new +
+
+
+ + + + + + + + + + + + + + @forelse ($material as $m) + + + + + + + + + + @empty + + + + @endforelse + +
{{__('#')}}{{__('Title')}}{{__('Course')}}{{__('Material Type')}}{{__('Content')}}{{__('Content Url')}}{{__('Action')}}
{{$m->id}}{{$m->title}}{{$m->course?->title_en}} + {{ $m->type == 'video' ? __('Video') : ($m->type == 'document' ? + __('Document') : __('Quiz')) }} + + + {{$m->content_url}} + + +
+ @csrf + @method('DELETE') +
+
No Course Material Found
+
+
+
+
+
+
+
+ +
+
+ +@endsection + +@push('scripts') + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/course/material/create.blade.php b/resources/views/backend/course/material/create.blade.php index a3b8aed..2bde2cd 100644 --- a/resources/views/backend/course/material/create.blade.php +++ b/resources/views/backend/course/material/create.blade.php @@ -52,17 +52,17 @@
- + @forelse ($lesson as $l) + @empty @endforelse
- @if($errors->has('courseId')) - {{ $errors->first('courseId') }} + @if($errors->has('lessonId')) + {{ $errors->first('lessonId') }} @endif
diff --git a/resources/views/backend/course/material/edit.blade.php b/resources/views/backend/course/material/edit.blade.php index 5a4bfe0..e9ce13f 100644 --- a/resources/views/backend/course/material/edit.blade.php +++ b/resources/views/backend/course/material/edit.blade.php @@ -54,18 +54,18 @@
- + @forelse ($lesson as $l) + @empty @endforelse
- @if($errors->has('courseId')) - {{ $errors->first('courseId') }} + @if($errors->has('lessonId')) + {{ $errors->first('lessonId') }} @endif
diff --git a/resources/views/backend/course/material/index.blade.php b/resources/views/backend/course/material/index.blade.php index 5914420..5f33b7c 100644 --- a/resources/views/backend/course/material/index.blade.php +++ b/resources/views/backend/course/material/index.blade.php @@ -53,7 +53,7 @@ class="nav-link btn-primary">Grid {{__('#')}} {{__('Title')}} - {{__('Course')}} + {{__('Lesson')}} {{__('Material Type')}} {{__('Content')}} {{__('Content Url')}} @@ -65,7 +65,7 @@ class="nav-link btn-primary">Grid {{$m->id}} {{$m->title}} - {{$m->course?->title_en}} + {{$m->lesson?->title}} {{ $m->type == 'video' ? __('Video') : ($m->type == 'document' ? __('Document') : __('Quiz')) }}