diff --git a/app/Http/Controllers/Backend/Courses/CourseCategoryController.php b/app/Http/Controllers/Backend/Courses/CourseCategoryController.php index 1f4565e..3974e6b 100644 --- a/app/Http/Controllers/Backend/Courses/CourseCategoryController.php +++ b/app/Http/Controllers/Backend/Courses/CourseCategoryController.php @@ -17,7 +17,7 @@ class CourseCategoryController extends Controller public function index() { $data = CourseCategory::paginate(10); - return view('backend.courses.courseCategory.index', compact('data')); + return view('backend.course.courseCategory.index', compact('data')); } /** @@ -25,7 +25,7 @@ public function index() */ public function create() { - return view('backend.courses.courseCategory.create'); + return view('backend.course.courseCategory.create'); } /** @@ -67,7 +67,7 @@ public function show(CourseCategory $courseCategory) public function edit($id) { $data = CourseCategory::findOrFail($id); - return view('backend.courses.courseCategory.edit', compact('data')); + return view('backend.course.courseCategory.edit', compact('data')); } /** diff --git a/app/Http/Controllers/Backend/Courses/CourseController.php b/app/Http/Controllers/Backend/Courses/CourseController.php index 68e22d2..162de55 100644 --- a/app/Http/Controllers/Backend/Courses/CourseController.php +++ b/app/Http/Controllers/Backend/Courses/CourseController.php @@ -5,6 +5,10 @@ use App\Http\Controllers\Controller; use App\Models\Course; use Illuminate\Http\Request; +use App\Models\CourseCategory; +use App\Models\Instructor; +use Exception; +use File; class CourseController extends Controller { @@ -13,7 +17,8 @@ class CourseController extends Controller */ public function index() { - // + $course = Course::paginate(10); + return view('backend.course.index', compact('course')); } /** @@ -21,7 +26,9 @@ public function index() */ public function create() { - // + $courseCategory = CourseCategory::get(); + $instructor = Instructor::get(); + return view('backend.course.create', compact('courseCategory', 'instructor')); } /** @@ -29,7 +36,35 @@ public function create() */ public function store(Request $request) { - // + try { + $course = new Course; + $course->title_en = $request->courseTitle_en; + $course->title_bn = $request->courseTitle_bn; + $course->description_en = $request->courseDescription_en; + $course->description_bn = $request->courseDescription_bn; + $course->category_id = $request->categoryId; + $course->instructor_id = $request->instructorId; + $course->type = $request->courseType; + $course->price = $request->coursePrice; + $course->subscription_price = $request->subscriptionPrice; + $course->difficulty = $request->courseDifficulty; + $course->prerequisites = $request->prerequisites; + $course->status = $request->status; + $course->language = 'en'; + + if ($request->hasFile('image')) { + $imageName = rand(111, 999) . time() . '.' . $request->image->extension(); + $request->image->move(public_path('uploads/courses'), $imageName); + $course->image = $imageName; + } + if ($course->save()) + return redirect()->route('course.index')->with('success', 'Data Saved'); + else + return redirect()->back()->withInput()->with('error', 'Please try again'); + } catch (Exception $e) { + dd($e); + return redirect()->back()->withInput()->with('error', 'Please try again'); + } } /** @@ -43,24 +78,63 @@ public function show(Course $course) /** * Show the form for editing the specified resource. */ - public function edit(Course $course) + public function edit($id) { - // + $courseCategory = CourseCategory::get(); + $instructor = Instructor::get(); + $course = Course::findOrFail(encryptor('decrypt', $id)); + return view('backend.course.edit', compact('courseCategory', 'instructor', 'course')); } /** * Update the specified resource in storage. */ - public function update(Request $request, Course $course) + public function update(Request $request, $id) { - // + try { + $course = Course::findOrFail(encryptor('decrypt', $id)); + $course->title_en = $request->courseTitle_en; + $course->title_bn = $request->courseTitle_bn; + $course->description_en = $request->courseDescription_en; + $course->description_bn = $request->courseDescription_bn; + $course->category_id = $request->categoryId; + $course->instructor_id = $request->instructorId; + $course->type = $request->courseType; + $course->price = $request->coursePrice; + $course->subscription_price = $request->subscriptionPrice; + $course->difficulty = $request->courseDifficulty; + $course->prerequisites = $request->prerequisites; + $course->status = $request->status; + $course->language = 'en'; + + if ($request->hasFile('image')) { + $imageName = rand(111, 999) . time() . '.' . $request->image->extension(); + $request->image->move(public_path('uploads/courses'), $imageName); + $course->image = $imageName; + } + if ($course->save()) + return redirect()->route('course.index')->with('success', 'Data Saved'); + else + return redirect()->back()->withInput()->with('error', 'Please try again'); + } catch (Exception $e) { + dd($e); + return redirect()->back()->withInput()->with('error', 'Please try again'); + } } /** * Remove the specified resource from storage. */ - public function destroy(Course $course) + public function destroy($id) { - // + $data = Course::findOrFail(encryptor('decrypt', $id)); + $image_path = public_path('uploads/courses') . $data->image; + + if ($data->delete()) { + if (File::exists($image_path)) + File::delete($image_path); + + return redirect()->back(); + } } } diff --git a/app/Http/Controllers/Backend/Instructors/InstructorController.php b/app/Http/Controllers/Backend/Instructors/InstructorController.php index 572891a..818936b 100644 --- a/app/Http/Controllers/Backend/Instructors/InstructorController.php +++ b/app/Http/Controllers/Backend/Instructors/InstructorController.php @@ -75,17 +75,45 @@ public function show(Instructor $instructor) /** * Show the form for editing the specified resource. */ - public function edit(Instructor $instructor) + public function edit($id) { - // + $role = Role::get(); + $instructor = Instructor::findOrFail(encryptor('decrypt', $id)); + return view('backend.instructor.edit', compact('role', 'instructor')); } /** * Update the specified resource in storage. */ - public function update(Request $request, Instructor $instructor) + public function update(Request $request, $id) { - // + try { + $instructor = Instructor::findOrFail(encryptor('decrypt', $id)); + $instructor->name_en = $request->fullName_en; + $instructor->name_bn = $request->fullName_bn; + $instructor->contact_en = $request->contactNumber_en; + $instructor->contact_bn = $request->contactNumber_bn; + $instructor->email = $request->emailAddress; + $instructor->role_id = $request->roleId; + $instructor->bio = $request->bio; + $instructor->status = $request->status; + $instructor->password = Hash::make($request->fullName_bn); + $instructor->language = 'en'; + $instructor->access_block = $request->access_block; + + if ($request->hasFile('image')) { + $imageName = rand(111, 999) . time() . '.' . $request->image->extension(); + $request->image->move(public_path('uploads/instructors'), $imageName); + $instructor->image = $imageName; + } + if ($instructor->save()) + return redirect()->route('instructor.index')->with('success', 'Data Saved'); + else + return redirect()->back()->withInput()->with('error', 'Please try again'); + } catch (Exception $e) { + dd($e); + return redirect()->back()->withInput()->with('error', 'Please try again'); + } } /** @@ -93,12 +121,12 @@ public function update(Request $request, Instructor $instructor) */ public function destroy($id) { - $data=Instructor::findOrFail(encryptor('decrypt',$id)); - $image_path=public_path('uploads/instructors').$data->image; + $data = Instructor::findOrFail(encryptor('decrypt', $id)); + $image_path = public_path('uploads/instructors') . $data->image; - if($data->delete()){ - if(File::exists($image_path)) - File::delete($image_path); + if ($data->delete()) { + if (File::exists($image_path)) + File::delete($image_path); return redirect()->back(); } diff --git a/app/Models/Course.php b/app/Models/Course.php index bd95f71..21248ec 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -8,4 +8,13 @@ class Course extends Model { use HasFactory; + + public function courseCategory() + { + return $this->belongsTo(CourseCategory::class, 'category_id', 'id'); + } + public function instructor() + { + return $this->belongsTo(Instructor::class); + } } diff --git a/app/Models/CourseCategory.php b/app/Models/CourseCategory.php index 3309859..cc002ba 100644 --- a/app/Models/CourseCategory.php +++ b/app/Models/CourseCategory.php @@ -8,4 +8,8 @@ class CourseCategory extends Model { use HasFactory; + + public function course(){ + return $this->hasMany(Course::class); + } } diff --git a/app/Models/Instructor.php b/app/Models/Instructor.php index 249ebaa..9d19eac 100644 --- a/app/Models/Instructor.php +++ b/app/Models/Instructor.php @@ -13,4 +13,8 @@ public function role() { return $this->belongsTo(Role::class); } + + public function courses(){ + return $this->hasMany(Course::class); + } } diff --git a/database/migrations/2023_11_26_034558_create_courses_table.php b/database/migrations/2023_11_26_034558_create_courses_table.php index 59322b8..1051797 100644 --- a/database/migrations/2023_11_26_034558_create_courses_table.php +++ b/database/migrations/2023_11_26_034558_create_courses_table.php @@ -19,9 +19,8 @@ public function up(): void $table->text('description_bn')->nullable(); $table->unsignedBigInteger('category_id')->index(); $table->unsignedBigInteger('instructor_id')->index(); - $table->decimal('price', 10, 2)->default(0.00); - $table->boolean('is_free')->default(false); - $table->boolean('is_subscription_based')->default(false); + $table->enum('type', ['free', 'paid', 'subscription'])->default('paid'); + $table->decimal('price', 10, 2)->default(0.00)->nullable(); $table->decimal('subscription_price', 10, 2)->nullable(); $table->text('prerequisites')->nullable(); $table->enum('difficulty', ['beginner', 'intermediate', 'advanced'])->nullable(); @@ -41,7 +40,7 @@ public function up(): void * Reverse the migrations. */ public function down(): void - { + { Schema::dropIfExists('courses'); } }; diff --git a/public/uploads/courses/2181700980174.jpg b/public/uploads/courses/2181700980174.jpg new file mode 100644 index 0000000..59f67cb Binary files /dev/null and b/public/uploads/courses/2181700980174.jpg differ diff --git a/public/uploads/courses/2841700979421.jpg b/public/uploads/courses/2841700979421.jpg new file mode 100644 index 0000000..bb7d075 Binary files /dev/null and b/public/uploads/courses/2841700979421.jpg differ diff --git a/public/uploads/courses/4211700982883.jpg b/public/uploads/courses/4211700982883.jpg new file mode 100644 index 0000000..f9ade61 Binary files /dev/null and b/public/uploads/courses/4211700982883.jpg differ diff --git a/public/uploads/courses/4791700981519.jpg b/public/uploads/courses/4791700981519.jpg new file mode 100644 index 0000000..bb7d075 Binary files /dev/null and b/public/uploads/courses/4791700981519.jpg differ diff --git a/public/uploads/courses/5251700979338.jpg b/public/uploads/courses/5251700979338.jpg new file mode 100644 index 0000000..bb7d075 Binary files /dev/null and b/public/uploads/courses/5251700979338.jpg differ diff --git a/public/uploads/courses/6261700979642.jpg b/public/uploads/courses/6261700979642.jpg new file mode 100644 index 0000000..59f67cb Binary files /dev/null and b/public/uploads/courses/6261700979642.jpg differ diff --git a/public/uploads/courses/7851700979325.jpg b/public/uploads/courses/7851700979325.jpg new file mode 100644 index 0000000..bb7d075 Binary files /dev/null and b/public/uploads/courses/7851700979325.jpg differ diff --git a/public/uploads/instructors/5371700969723.jpg b/public/uploads/instructors/5371700969723.jpg new file mode 100644 index 0000000..876e71f Binary files /dev/null and b/public/uploads/instructors/5371700969723.jpg differ diff --git a/public/uploads/instructors/7141700979525.jpg b/public/uploads/instructors/7141700979525.jpg new file mode 100644 index 0000000..a12b602 Binary files /dev/null and b/public/uploads/instructors/7141700979525.jpg differ diff --git a/resources/views/backend/Courses/courseCategory/create.blade.php b/resources/views/backend/course/courseCategory/create.blade.php similarity index 100% rename from resources/views/backend/Courses/courseCategory/create.blade.php rename to resources/views/backend/course/courseCategory/create.blade.php diff --git a/resources/views/backend/Courses/courseCategory/edit.blade.php b/resources/views/backend/course/courseCategory/edit.blade.php similarity index 100% rename from resources/views/backend/Courses/courseCategory/edit.blade.php rename to resources/views/backend/course/courseCategory/edit.blade.php diff --git a/resources/views/backend/Courses/courseCategory/index.blade.php b/resources/views/backend/course/courseCategory/index.blade.php similarity index 100% rename from resources/views/backend/Courses/courseCategory/index.blade.php rename to resources/views/backend/course/courseCategory/index.blade.php diff --git a/resources/views/backend/course/create.blade.php b/resources/views/backend/course/create.blade.php new file mode 100644 index 0000000..675eac3 --- /dev/null +++ b/resources/views/backend/course/create.blade.php @@ -0,0 +1,206 @@ +@extends('backend.layouts.app') +@section('title', 'Add Course') + +@push('styles') + + + +@endpush + +@section('content') + +
+ +
+ +
+
+
+

Add Course

+
+
+
+ +
+
+ +
+
+
+
+
Basic Info
+
+
+
+ @csrf +
+
+
+ + +
+ @if($errors->has('courseTitle_en')) + {{ $errors->first('courseTitle_en') }} + @endif +
+
+
+ + +
+
+
+
+ + +
+ @if($errors->has('courseDescription_en')) + {{ $errors->first('courseDescription_en') }} + @endif +
+
+
+ + +
+ @if($errors->has('courseDescription_bn')) + {{ $errors->first('courseDescription_bn') }} + @endif +
+
+
+ + +
+ @if($errors->has('categoryId')) + {{ $errors->first('categoryId') }} + @endif +
+
+
+ + +
+ @if($errors->has('instructorId')) + {{ $errors->first('instructorId') }} + @endif +
+
+
+ + +
+
+
+
+ + +
+ @if($errors->has('coursePrice')) + {{ $errors->first('coursePrice') }} + @endif +
+
+
+ + +
+ @if($errors->has('subscription_price')) + {{ $errors->first('subscription_price') }} + @endif +
+
+
+ + +
+
+
+
+ + +
+ @if($errors->has('prerequisites')) + {{ $errors->first('prerequisites') }} + @endif +
+
+
+ + +
+
+
+ +
+ +
+
+
+ + +
+
+
+
+
+
+
+ +
+
+ +@endsection + +@push('scripts') + + + + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/course/edit.blade.php b/resources/views/backend/course/edit.blade.php new file mode 100644 index 0000000..b00c4cc --- /dev/null +++ b/resources/views/backend/course/edit.blade.php @@ -0,0 +1,234 @@ +@extends('backend.layouts.app') +@section('title', 'Edit Instructor') + +@push('styles') + + + +@endpush + +@section('content') + +
+ +
+ +
+
+
+

Edit Course

+
+
+
+ +
+
+ +
+
+
+
+
Basic Info
+
+
+
+ @csrf + @method('PATCH') + +
+
+
+ + +
+ @if($errors->has('courseTitle_en')) + {{ $errors->first('courseTitle_en') }} + @endif +
+
+
+ + +
+
+
+
+ + +
+ @if($errors->has('courseDescription_en')) + {{ $errors->first('courseDescription_en') }} + @endif +
+
+
+ + +
+ @if($errors->has('courseDescription_bn')) + {{ $errors->first('courseDescription_bn') }} + @endif +
+
+
+ + +
+ @if($errors->has('categoryId')) + {{ $errors->first('categoryId') }} + @endif +
+
+
+ + +
+ @if($errors->has('instructorId')) + {{ $errors->first('instructorId') }} + @endif +
+
+
+ + +
+ @if($errors->has('courseType')) + {{ $errors->first('courseType') }} + @endif +
+
+
+ + +
+ @if($errors->has('coursePrice')) + {{ $errors->first('coursePrice') }} + @endif +
+
+
+ + +
+ @if($errors->has('subscription_price')) + {{ $errors->first('subscription_price', + $course->subscription_price) }} + @endif +
+
+
+ + +
+ @if($errors->has('courseDifficulty')) + {{ $errors->first('courseDifficulty') }} + @endif +
+
+
+ + +
+ @if($errors->has('prerequisites')) + {{ $errors->first('prerequisites') }} + @endif +
+
+
+ + +
+
+
+
+ + +
+ @if($errors->has('password')) + {{ $errors->first('password') }} + @endif +
+
+ +
+ +
+
+
+ + +
+
+
+
+
+
+
+ +
+
+ +@endsection + +@push('scripts') + + + + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/course/index.blade.php b/resources/views/backend/course/index.blade.php new file mode 100644 index 0000000..ab63289 --- /dev/null +++ b/resources/views/backend/course/index.blade.php @@ -0,0 +1,119 @@ +@extends('backend.layouts.app') +@section('title', 'Course List') + +@push('styles') + + +@endpush + +@section('content') + +
+ +
+ +
+
+
+

Course List

+
+
+ +
+ +
+
+
+
+ + Add new +
+
+
+ @forelse ($course as $d) +
+
+
+ +
+
+
+
+ +
+

{{$d->title_en}}

+
    +
  • + Difficulty + {{ $d->difficulty == 'beginner' ? __('Beginner') : ($d->gender == 'intermediate' ? __('Intermediate') : __('Advanced')) }} +
  • +
  • + Instructor : + {{$d->instructor?->name_en}} +
  • +
  • + Category : + {{$d->courseCategory?->category_name}} +
  • +
  • + Type : + {{ $d->type == 'free' ? __('Free') : ($d->gender == 'paid' ? __('Paid') : + __('Subscription')) }} +
  • +
  • + Price : + ${{$d->price}} +
  • +
+ Read More +
+
+
+
+ @empty +
+
+
+
+

Course Not Found

+
+
+
+
+ @endforelse +
+
+
+
+
+ +
+
+ +@endsection + +@push('scripts') + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/instructor/edit.blade.php b/resources/views/backend/instructor/edit.blade.php index b988762..1afb213 100644 --- a/resources/views/backend/instructor/edit.blade.php +++ b/resources/views/backend/instructor/edit.blade.php @@ -1,5 +1,5 @@ @extends('backend.layouts.app') -@section('title', 'Edit Student') +@section('title', 'Edit Instructor') @push('styles') @@ -16,14 +16,14 @@
-

Edit Student

+

Edit Instructor

@@ -35,16 +35,17 @@
Basic Info
-
+ @csrf @method('PATCH') - +
+ value="{{old('fullName_en',$instructor->name_en)}}">
@if($errors->has('fullName_en')) {{ $errors->first('fullName_en') }} @@ -54,14 +55,14 @@
+ value="{{old('fullName_bn',$instructor->name_bn)}}">
+ value="{{old('contactNumber_en',$instructor->contact_en)}}">
@if($errors->has('contactNumber_en')) {{ $errors->first('contactNumber_en') }} @@ -71,7 +72,7 @@
+ value="{{old('contactNumber_bn',$instructor->contact_bn)}}">
@if($errors->has('contactNumber_bn')) {{ $errors->first('contactNumber_bn') }} @@ -81,7 +82,7 @@
+ value="{{old('emailAddress',$instructor->email)}}">
@if($errors->has('emailAddress')) {{ $errors->first('emailAddress') }} @@ -92,7 +93,8 @@ + +
- @if($errors->has('birthDate')) - {{ $errors->first('birthDate') }} + @if($errors->has('bio')) + {{ $errors->first('bio') }} @endif
-
-
- - -
-
diff --git a/resources/views/backend/instructor/index.blade.php b/resources/views/backend/instructor/index.blade.php index d35132f..80bd5a0 100644 --- a/resources/views/backend/instructor/index.blade.php +++ b/resources/views/backend/instructor/index.blade.php @@ -70,7 +70,7 @@ class="nav-link btn-primary mr-1 show active">List View {{$d->email}} {{$d->contact_en}} {{$d->role?->name}} - {{$d->contact_en}} + {{$d->bio}} @if($d->status==1){{__('Active')}} diff --git a/resources/views/backend/layouts/app.blade.php b/resources/views/backend/layouts/app.blade.php index 9a6b317..ce7a09a 100644 --- a/resources/views/backend/layouts/app.blade.php +++ b/resources/views/backend/layouts/app.blade.php @@ -254,10 +254,10 @@ class="feather feather-log-out"> Courses
  • @@ -108,69 +108,6 @@ class="nav-link btn-primary mr-1 show active">List View - {{--
    -
    - @forelse ($data as $d) -
    -
    -
    - -
    -
    -
    -
    - -
    -

    {{$d->name_en}}

    -

    {{$d->role?->type}}

    -
      -
    • - #Sl.{{$d->id}} -
    • -
    • - Phone No. - :{{$d->contact_en}} -
    • -
    • - Email:{{$d->email}} -
    • -
    • - Created At. - :{{$d->created_at}} -
    • -
    - Read More -
    -
    -
    -
    - @empty -
    -
    -
    -
    -

    User Not Found

    -
    -
    -
    -
    - @endforelse -
    -
    --}} diff --git a/resources/views/backend/role/index.blade.php b/resources/views/backend/role/index.blade.php index 9470093..9d6a736 100644 --- a/resources/views/backend/role/index.blade.php +++ b/resources/views/backend/role/index.blade.php @@ -32,8 +32,8 @@
    diff --git a/routes/web.php b/routes/web.php index ac908b8..b097dde 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,6 +9,7 @@ use App\Http\Controllers\Backend\PermissionController as permission; use App\Http\Controllers\Backend\Students\StudentController as student; use App\Http\Controllers\Backend\Instructors\InstructorController as instructor; +use App\Http\Controllers\Backend\Courses\CourseController as course; /* |-------------------------------------------------------------------------- @@ -34,14 +35,14 @@ }); Route::middleware(['checkrole'])->prefix('admin')->group(function () { - Route::resource('user',user::class); - Route::resource('role',role::class); - Route::get('permission/{role}',[permission::class,'index'])->name('permission.list'); - Route::post('permission/{role}',[permission::class,'save'])->name('permission.save'); - Route::resource('courseCategory', courseCategory::class); + Route::resource('user', user::class); + Route::resource('role', role::class); Route::resource('student', student::class); Route::resource('instructor', instructor::class); - + Route::resource('courseCategory', courseCategory::class); + Route::resource('course', course::class); + Route::get('permission/{role}', [permission::class, 'index'])->name('permission.list'); + Route::post('permission/{role}', [permission::class, 'save'])->name('permission.save'); }); @@ -55,4 +56,3 @@ // Route::get('/dashboard', function () { // return view('welcome'); // })->name('dashboard'); - \ No newline at end of file