diff --git a/app/Http/Controllers/DiscussionController.php b/app/Http/Controllers/Backend/Communication/DiscussionController.php similarity index 85% rename from app/Http/Controllers/DiscussionController.php rename to app/Http/Controllers/Backend/Communication/DiscussionController.php index 8698f4d..9af00d5 100644 --- a/app/Http/Controllers/DiscussionController.php +++ b/app/Http/Controllers/Backend/Communication/DiscussionController.php @@ -1,6 +1,6 @@ question_id = $request->questionId; + $option->option_text = $request->optionText; + $option->is_correct = $request->is_correct; + + if ($option->save()) { + $this->notice::success('Data Saved'); + return redirect()->route('option.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(Option $option) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit($id) + { + $question = Question::get(); + $option = Option::findOrFail(encryptor('decrypt', $id)); + return view('backend.quiz.option.edit', compact('question', 'option')); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, $id) + { + try { + $option = Option::findOrFail(encryptor('decrypt', $id)); + $option->question_id = $request->questionId; + $option->option_text = $request->optionText; + $option->is_correct = $request->is_correct; + + if ($option->save()) { + $this->notice::success('Data Saved'); + return redirect()->route('option.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($id) + { + $data = Option::findOrFail(encryptor('decrypt', $id)); + if ($data->delete()) { + $this->notice::error('Data Deleted!'); + return redirect()->back(); + } + } +} diff --git a/app/Http/Controllers/Backend/Quizzes/QuestionController.php b/app/Http/Controllers/Backend/Quizzes/QuestionController.php index fe04ccc..5c73b81 100644 --- a/app/Http/Controllers/Backend/Quizzes/QuestionController.php +++ b/app/Http/Controllers/Backend/Quizzes/QuestionController.php @@ -1,6 +1,6 @@ belongsTo(Student::class); + } + + public function question() + { + return $this->belongsTo(Question::class); + } } diff --git a/app/Models/Course.php b/app/Models/Course.php index 7866a72..6f52f22 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -28,4 +28,14 @@ public function quiz() { return $this->hasMany(Quiz::class); } + + public function review() + { + return $this->hasMany(Review::class); + } + + public function discussion() + { + return $this->hasMany(Discussion::class); + } } diff --git a/app/Models/Discussion.php b/app/Models/Discussion.php index 934a571..3b757e2 100644 --- a/app/Models/Discussion.php +++ b/app/Models/Discussion.php @@ -8,4 +8,14 @@ class Discussion extends Model { use HasFactory; + + public function user() + { + return $this->belongsTo(User::class); + } + + public function course() + { + return $this->belongsTo(Course::class); + } } diff --git a/app/Models/Message.php b/app/Models/Message.php index b9f7393..ed8e137 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -8,4 +8,9 @@ class Message extends Model { use HasFactory; + + public function user() + { + return $this->belongsTo(User::class); + } } diff --git a/app/Models/Option.php b/app/Models/Option.php new file mode 100644 index 0000000..ad2c842 --- /dev/null +++ b/app/Models/Option.php @@ -0,0 +1,16 @@ +belongsTo(Question::class); + } +} diff --git a/app/Models/Question.php b/app/Models/Question.php index fdc70a3..d8c78ae 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -12,4 +12,13 @@ class Question extends Model public function quiz(){ return $this->belongsTo(Quiz::class); } + + public function option(){ + return $this->hasMany(Option::class); + } + + public function answer() + { + return $this->hasMany(Answer::class); + } } diff --git a/app/Models/Review.php b/app/Models/Review.php index b63a133..f5271e0 100644 --- a/app/Models/Review.php +++ b/app/Models/Review.php @@ -8,4 +8,14 @@ class Review extends Model { use HasFactory; + + public function student() + { + return $this->belongsTo(Student::class); + } + + public function course() + { + return $this->belongsTo(Course::class); + } } diff --git a/app/Models/Student.php b/app/Models/Student.php index c720c69..bba1a4e 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -13,4 +13,14 @@ public function role() { return $this->belongsTo(Role::class); } + + public function answer() + { + return $this->hasMany(Answer::class); + } + + public function review() + { + return $this->hasMany(Review::class); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 1b864e6..0636309 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -35,4 +35,14 @@ public function role() { return $this->belongsTo(Role::class); } + + public function discussion() + { + return $this->hasMany(Discussion::class); + } + + public function message() + { + return $this->hasMany(Message::class); + } } diff --git a/database/migrations/2023_11_26_153660_create_options_table.php b/database/migrations/2023_11_26_153660_create_options_table.php new file mode 100644 index 0000000..bfac264 --- /dev/null +++ b/database/migrations/2023_11_26_153660_create_options_table.php @@ -0,0 +1,33 @@ +id(); + $table->unsignedBigInteger('question_id')->index(); + $table->string('option_text'); + $table->boolean('is_correct')->default(false); + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('options'); + } +}; diff --git a/database/migrations/2023_11_26_153719_create_answers_table.php b/database/migrations/2023_11_26_153719_create_answers_table.php index 32b337a..5ed79c1 100644 --- a/database/migrations/2023_11_26_153719_create_answers_table.php +++ b/database/migrations/2023_11_26_153719_create_answers_table.php @@ -14,7 +14,7 @@ public function up(): void Schema::create('answers', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('student_id')->index(); - $table->unsignedBigInteger('question_id')->index(); + $table->unsignedBigInteger('question_id')->index(); $table->text('answer')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/database/migrations/2023_11_26_153735_create_reviews_table.php b/database/migrations/2023_11_26_153735_create_reviews_table.php index 8401ccd..fc9f381 100644 --- a/database/migrations/2023_11_26_153735_create_reviews_table.php +++ b/database/migrations/2023_11_26_153735_create_reviews_table.php @@ -17,7 +17,7 @@ public function up(): void $table->unsignedBigInteger('course_id')->index(); $table->integer('rating'); $table->text('comment')->nullable(); - $table->timestamps(); + $table->timestamps(); $table->softDeletes(); $table->foreign('student_id')->references('id')->on('students')->onDelete('cascade'); diff --git a/database/migrations/2023_11_26_153902_create_discussions_table.php b/database/migrations/2023_11_26_153902_create_discussions_table.php index f7f0379..bf7e945 100644 --- a/database/migrations/2023_11_26_153902_create_discussions_table.php +++ b/database/migrations/2023_11_26_153902_create_discussions_table.php @@ -21,7 +21,7 @@ public function up(): void $table->softDeletes(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('course_id')->references('id')->on('courses')->onDelete('cascade'); + $table->foreign('course_id')->references('id')->on('courses')->onDelete('cascade'); }); } diff --git a/database/migrations/2023_11_26_153916_create_messages_table.php b/database/migrations/2023_11_26_153916_create_messages_table.php index 3ff9a8c..b7fa7b6 100644 --- a/database/migrations/2023_11_26_153916_create_messages_table.php +++ b/database/migrations/2023_11_26_153916_create_messages_table.php @@ -20,7 +20,7 @@ public function up(): void $table->softDeletes(); $table->foreign('sender_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('receiver_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('receiver_id')->references('id')->on('users')->onDelete('cascade'); }); } diff --git a/eLearning.sql b/eLearning.sql index f42f6fd..b389321 100644 --- a/eLearning.sql +++ b/eLearning.sql @@ -139,12 +139,21 @@ CREATE TABLE questions ( FOREIGN KEY (quiz_id) REFERENCES quizzes(id) ); +-- Introduced a new table for multiple-choice options +CREATE TABLE options ( + id INT PRIMARY KEY AUTO_INCREMENT, + question_id INT, + option_text VARCHAR(255) NOT NULL, + is_correct BOOLEAN DEFAULT false, + FOREIGN KEY (question_id) REFERENCES questions(id) +); + -- User_answers table stores user responses to quiz questions CREATE TABLE user_answers ( id INT PRIMARY KEY AUTO_INCREMENT, student_id INT, question_id INT, - answer TEXT, + answer TEXT, is_correct BOOLEAN, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (student_id) REFERENCES students(id), diff --git a/resources/views/backend/communication/discussion/index.blade.php b/resources/views/backend/communication/discussion/index.blade.php new file mode 100644 index 0000000..541bb1f --- /dev/null +++ b/resources/views/backend/communication/discussion/index.blade.php @@ -0,0 +1,109 @@ +@extends('backend.layouts.app') +@section('title', 'Discussion List') + +@push('styles') + + +@endpush + +@section('content') + +