Project Introduction

The Online Quiz Platform is an interactive web-based application designed to facilitate the creation, distribution, and management of quizzes and assessments. This system aims to provide educators, trainers, and organizations with a powerful tool to evaluate knowledge and skills in a flexible and engaging manner. With the increasing demand for online learning and assessment solutions, the Online Quiz Platform addresses these needs by offering a user-friendly interface and robust functionalities for both quiz creators and participants.

The platform features capabilities for creating various types of quizzes, including multiple-choice, true/false, and short answer questions. Users can easily customize quizzes, set time limits, and track participant performance in real-time. Additionally, the system includes analytics tools to provide insights into quiz results and participant engagement. By automating the quiz process, the Online Quiz Platform aims to enhance the learning experience and streamline assessment procedures for educators and organizations.

Project Objectives

  • To develop an intuitive interface for users to create, manage, and participate in quizzes.
  • To implement various question types and customizable quiz settings for flexibility.
  • To provide real-time feedback and scoring for participants upon quiz completion.
  • To enable tracking of participant performance and analytics for quiz creators.
  • To facilitate user registration and profile management for personalized experiences.
  • To ensure data security and privacy for all user information and quiz results.
  • To enhance user engagement through features like leaderboards and certificates of completion.
  • To support mobile responsiveness for access on various devices.

Project Modules

1. User Management Module

  • User Registration/Login: Allow users (students, teachers, or administrators) to create accounts and log in securely.
  • Profile Management: Enable users to manage their profiles, including personal information, profile pictures, and preferences.
  • Role Management: Differentiate between user roles (e.g., admin, instructor, student) with varying permissions.

2. Quiz Creation and Management Module

  • Quiz Builder: Provide tools for instructors to create quizzes, including question types (multiple choice, true/false, short answer, etc.).
  • Question Bank: Allow instructors to create and manage a repository of questions for reuse in multiple quizzes.
  • Quiz Settings: Enable customization of quiz settings, such as time limits, scoring methods, and randomization of questions.

3. Quiz Participation Module

  • User Interface for Quizzes: Provide an intuitive interface for users to take quizzes, including navigation and question display.
  • Timer: Implement a countdown timer for quizzes with time limits.
  • Auto-Save Progress: Allow users to save their progress and resume later if needed.

4. Scoring and Feedback Module

  • Automatic Grading: Automatically grade quizzes based on predefined answers and provide instant feedback.
  • Detailed Results: Provide users with detailed results, including scores, correct answers, and explanations for each question.
  • Performance Analytics: Offer insights into user performance over time, including strengths and weaknesses.

5. Leaderboard and Ranking Module

  • Leaderboard Display: Show rankings of users based on their quiz scores, encouraging competition.
  • Achievements and Badges: Award badges or achievements for completing quizzes or reaching certain milestones.

6. Reporting and Analytics Module

  • Quiz Performance Reports: Generate reports for instructors on quiz performance, including average scores and question difficulty.
  • User Activity Reports: Track user engagement and participation in quizzes over time.

7. Admin Dashboard Module

  • User Management: Admins can manage users, including banning or promoting users.
  • Quiz Management: Admins can oversee all quizzes, including editing, deleting, or archiving quizzes.
  • System Settings: Manage platform-wide settings, including user roles, permissions, and notifications.

8. Notification System

  • Email Notifications: Send notifications for quiz availability, reminders, and results.
  • In-app Notifications: Provide real-time notifications within the platform for important updates.

9. Security and Access Control Module

  • Data Security: Ensure that user data is stored securely and access is controlled based on roles.
  • Anti-Cheat Mechanisms: Implement measures to prevent cheating, such as randomizing questions and monitoring user behavior during quizzes.

Project Tables Queries


-- Create Users Table
CREATE TABLE Users (
UserId INT PRIMARY KEY IDENTITY(1,1),
Username NVARCHAR(50) NOT NULL UNIQUE,
PasswordHash NVARCHAR(256) NOT NULL,
Email NVARCHAR(100) NOT NULL UNIQUE,
RoleId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (RoleId) REFERENCES Roles(RoleId)
);
-- Create Roles Table
CREATE TABLE Roles (
RoleId INT PRIMARY KEY IDENTITY(1,1),
RoleName NVARCHAR(50) NOT NULL UNIQUE
);
-- Create Quizzes Table
CREATE TABLE Quizzes (
QuizId INT PRIMARY KEY IDENTITY(1,1),
Title NVARCHAR(100) NOT NULL,
Description NVARCHAR(MAX),
CreatedAt DATETIME DEFAULT GETDATE(),
CreatedBy INT,
FOREIGN KEY (CreatedBy) REFERENCES Users(UserId)
);
-- Create Questions Table
CREATE TABLE Questions (
QuestionId INT PRIMARY KEY IDENTITY(1,1),
QuizId INT,
QuestionText NVARCHAR(MAX) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (QuizId) REFERENCES Quizzes(QuizId)
);
-- Create Answers Table
CREATE TABLE Answers (
AnswerId INT PRIMARY KEY IDENTITY(1,1),
QuestionId INT,
AnswerText NVARCHAR(MAX) NOT NULL,
IsCorrect BIT NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (QuestionId) REFERENCES Questions(QuestionId)
);
-- Create Scores Table
CREATE TABLE Scores (
ScoreId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
QuizId INT,
Score INT NOT NULL,
AttemptedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId),
FOREIGN KEY (QuizId) REFERENCES Quizzes(QuizId)
);
-- Create Performance Table
CREATE TABLE Performance (
PerformanceId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
TotalQuizzes INT NOT NULL,
TotalScore INT NOT NULL,
AverageScore DECIMAL(5, 2) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create Notifications Table
CREATE TABLE Notifications (
NotificationId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
Message NVARCHAR(256) NOT NULL,
IsRead BIT DEFAULT 0,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create Achievements Table
CREATE TABLE Achievements (
AchievementId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
Title NVARCHAR(100) NOT NULL,
Description NVARCHAR(MAX),
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);

Explanation of the Tables

Users: Stores user information, including username, password hash, email, and role.

Roles: Defines user roles (e.g., Admin, User).

Quizzes: Contains quiz details, including title, description, creation date, and creator.

Questions: Stores questions associated with quizzes, including the question text and creation date.

Answers: Contains possible answers for each question, indicating which answer is correct.

Scores: Tracks user scores for each quiz attempt, including the user ID, quiz ID, score, and attempt date.

Performance: Stores performance metrics for users, including total quizzes taken, total score, and average score.

Notifications: Manages notifications for users, such as alerts for new quizzes or achievements.

Achievements: Stores achievements earned by users, including title and description.

To create the models and migrations for the provided MySQL schema in Laravel 11, you can follow these steps.

Below, I will provide the migration files and the corresponding Eloquent models for each table.

Step 1: Create Migrations

You can create migrations using the Artisan command line tool. For each table, you will create a migration file. Here are the migration files based on your SQL schema:

1. Create Users Table Migration

database/migrations/2025_02_01_000001_create_users_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id('User Id');
$table->string('Username', 50)->unique();
$table->string('PasswordHash', 256);
$table->string('Email', 100)->unique();
$table->foreignId('RoleId')->nullable()->constrained('roles', 'RoleId');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('users');
}
}

2. Create Roles Table Migration

database/migrations/2025_02_01_000002_create_roles_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id('RoleId');
$table->string('RoleName', 50)->unique();
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}

3. Create Quizzes Table Migration

database/migrations/2025_02_01_000003_create_quizzes_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateQuizzesTable extends Migration
{
public function up()
{
Schema::create('quizzes', function (Blueprint $table) {
$table->id('QuizId');
$table->string('Title', 100);
$table->text('Description')->nullable();
$table->foreignId('CreatedBy')->constrained('users', 'User Id');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('quizzes');
}
}

4. Create Questions Table Migration

database/migrations/2025_02_01_000004_create_questions_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateQuestionsTable extends Migration
{
public function up()
{
Schema::create('questions', function (Blueprint $table) {
$table->id('QuestionId');
$table->foreignId('QuizId')->constrained('quizzes', 'QuizId');
$table->text('QuestionText');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('questions');
}
}

5. Create Answers Table Migration

database/migrations/2025_02_01_000005_create_answers_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAnswersTable extends Migration
{
public function up()
{
Schema::create('answers', function (Blueprint $table) {
$table->id('AnswerId');
$table->foreignId('QuestionId')->constrained('questions', 'QuestionId');
$table->text('AnswerText');
$table->boolean('IsCorrect');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('answers');
}
}

6. Create Scores Table Migration

database/migrations/2025_02_01_000006_create_scores_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateScoresTable extends Migration
{
public function up()
{
Schema::create('scores', function (Blueprint $table) {
$table->id('ScoreId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->foreignId('QuizId')->constrained('quizzes', 'QuizId');
$table->integer('Score');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('scores');
}
}

7. Create Performance Table Migration

database/migrations/2025_02_01_000007_create_performance_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePerformanceTable extends Migration
{
public function up()
{
Schema::create('performance', function (Blueprint $table) {
$table->id('PerformanceId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->integer('TotalQuizzes');
$table->integer('TotalScore');
$table->decimal('AverageScore', 5, 2);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('performance');
}
}

8. Create Notifications Table Migration

database/migrations/2025_02_01_000008_create_notifications_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateNotificationsTable extends Migration
{
public function up()
{
Schema::create('notifications', function (Blueprint $table) {
$table->id('NotificationId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->string('Message', 256);
$table->boolean('IsRead')->default(0);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('notifications');
}
}

9. Create Achievements Table Migration

database/migrations/2025_02_01_000009_create_achievements_table.php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAchievementsTable extends Migration
{
public function up()
{
Schema::create('achievements', function (Blueprint $table) {
$table->id('AchievementId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->string('Title', 100);
$table->text('Description')->nullable();
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('achievements');
}
}

Step 2: Create Eloquent Models

Next, you will create Eloquent models for each of the tables. Here are the models corresponding to the migrations:

1. User Model

// app/Models/User.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasFactory;
protected $table = 'users';
protected $fillable = [
'Username',
'PasswordHash',
'Email',
'RoleId',
];
public function roles()
{
return $this->belongsTo(Role::class, 'RoleId');
}
public function quizzes()
{
return $this->hasMany(Quiz::class, 'CreatedBy');
}
public function scores()
{
return $this->hasMany(Score::class, 'User Id');
}
public function performances()
{
return $this->hasOne(Performance::class, 'User Id');
}
public function notifications()
{
return $this->hasMany(Notification::class, 'User Id');
}
public function achievements()
{
return $this->hasMany(Achievement::class, 'User Id');
}
}

2. Role Model

// app/Models/Role.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
use HasFactory;
protected $table = 'roles';
protected $fillable = [
'RoleName',
];
public function users()
{
return $this->hasMany(User::class, 'RoleId');
}
}

3. Quiz Model

// app/Models/Quiz.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Quiz extends Model
{
use HasFactory;
protected $table = 'quizzes';
protected $fillable = [
'Title',
'Description',
'CreatedBy',
];
public function questions()
{
return $this->hasMany(Question::class, 'QuizId');
}
public function creator()
{
return $this->belongsTo(User::class, 'CreatedBy');
}
}

4. Question Model

// app/Models/Question.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Question extends Model
{
use HasFactory;
protected $table = 'questions';
protected $fillable = [
'QuizId',
'QuestionText',
];
public function quiz()
{
return $this->belongsTo(Quiz::class, 'QuizId');
}
public function answers()
{
return $this->hasMany(Answer::class, 'QuestionId');
}
}

5. Answer Model

// app/Models/Answer.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Answer extends Model
{
use HasFactory;
protected $table = 'answers';
protected $fillable = [
'QuestionId',
'AnswerText',
'IsCorrect',
];
public function question()
{
return $this->belongsTo(Question::class, 'QuestionId');
}
}

6. Score Model

// app/Models/Score.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Score extends Model
{
use HasFactory;
protected $table = 'scores';
protected $fillable = [
'User Id',
'QuizId',
'Score',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
public function quiz()
{
return $this->belongsTo(Quiz::class, 'QuizId');
}
}

7. Performance Model

// app/Models/Performance.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Performance extends Model
{
use HasFactory;
protected $table = 'performance';
protected $fillable = [
'User Id',
'TotalQuizzes',
'TotalScore',
'AverageScore',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
}

8. Notification Model

// app/Models/Notification.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
use HasFactory;
protected $table = 'notifications';
protected $fillable = [
'User Id',
'Message',
'IsRead',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
}

9. Achievement Model

// app/Models/Achievement.php


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Achievement extends Model
{
use HasFactory;
protected $table = 'achievements';
protected $fillable = [
'User Id',
'Title',
'Description',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
}

Step 3: Run Migrations

After creating the migration files and models, you can run the migrations using the following command:


php artisan migrate

This will create the tables in your database according to the defined schema. You can now use the Eloquent models to interact with the database in your Laravel application.

To create controllers for each model with complete CRUD operations in Laravel, you can use the Artisan command line tool to generate the controllers.

Below, I will provide the code for each controller, including methods for creating, reading, updating, and deleting records, as well as the necessary views.

Step 1: Generate Controllers

You can generate controllers using the following Artisan command:


php artisan make:controller UserController --resource
php artisan make:controller RoleController --resource
php artisan make:controller QuizController --resource
php artisan make:controller QuestionController --resource
php artisan make:controller AnswerController --resource
php artisan make:controller ScoreController --resource
php artisan make:controller PerformanceController --resource
php artisan make:controller NotificationController --resource
php artisan make:controller AchievementController --resource

Step 2: Implement CRUD Operations

Below are the implementations for each controller. Each controller will have methods for the following operations:

index(): Display a listing of the resource.

create(): Show the form for creating a new resource.

store(): Store a newly created resource in storage.

show(): Display the specified resource.

edit(): Show the form for editing the specified resource.

update(): Update the specified resource in storage.

destroy(): Remove the specified resource from storage.

1. UserController

// app/Http/Controllers/UserController.php


namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index()
{
$users = User::all();
return view('users.index', compact('users'));
}
public function create()
{
return view('users.create');
}
public function store(Request $request)
{
$request->validate([
'Username' => 'required|unique:users|max:50',
'PasswordHash' => 'required',
'Email' => 'required|email|unique:users|max:100',
'RoleId' => 'nullable|exists:roles,RoleId',
]);
User::create($request->all());
return redirect()->route('users.index')->with('success', 'User created successfully.');
}
public function show(User $user)
{
return view('users.show', compact('user'));
}
public function edit(User $user)
{
return view('users.edit', compact('user'));
}
public function update(Request $request, User $user)
{
$request->validate([
'Username' => 'required|max:50|unique:users,Username,' . $user->id,
'PasswordHash' => 'required',
'Email' => 'required|email|max:100|unique:users,Email,' . $user->id,
'RoleId' => 'nullable|exists:roles,RoleId',
]);
$user->update($request->all());
return redirect()->route('users.index')->with('success', 'User updated successfully.');
}
public function destroy(User $user)
{
$user->delete();
return redirect()->route('users.index')->with('success', 'User deleted successfully.');
}
}

2. RoleController

// app/Http/Controllers/RoleController.php


namespace App\Http\Controllers;
use App\Models\Role;
use Illuminate\Http\Request;
class RoleController extends Controller
{
public function index()
{
$roles = Role::all();
return view('roles.index', compact('roles'));
}
public function create()
{
return view('roles.create');
}
public function store(Request $request)
{
$request->validate([
'RoleName' => 'required|unique:roles|max:50',
]);
Role::create($request->all());
return redirect()->route('roles.index')->with('success', 'Role created successfully.');
}
public function show(Role $role)
{
return view('roles.show', compact('role'));
}
public function edit(Role $role)
{
return view('roles.edit', compact('role'));
}
public function update(Request $request, Role $role)
{
$request->validate([
'RoleName' => 'required|max:50|unique:roles,RoleName,' . $role->id,
]);
$role->update($request->all());
return redirect()->route('roles.index')->with('success', 'Role updated successfully.');
}
public function destroy(Role $role)
{
$role->delete();
return redirect()->route('roles.index')->with('success', 'Role deleted successfully.');
}
}

3. QuizController

// app/Http/Controllers/QuizController.php


namespace App\Http\Controllers;
use App\Models\Quiz;
use App\Models\User;
use Illuminate\Http\Request;
class QuizController extends Controller
{
public function index()
{
$quizzes = Quiz::all();
return view('quizzes.index', compact('quizzes'));
}
public function create()
{
$users = User::all();
return view('quizzes.create', compact('users'));
}
public function store(Request $request)
{
$request->validate([
'Title' => 'required|max:100',
'Description' => 'nullable',
'CreatedBy' => 'required|exists:users,User Id',
]);
Quiz::create($request->all());
return redirect()->route('quizzes.index')->with('success', 'Quiz created successfully.');
}
public function show(Quiz $quiz)
{
return view('quizzes.show', compact('quiz'));
}
public function edit(Quiz $quiz)
{
$users = User::all();
return view('quizzes.edit', compact('quiz', 'users'));
}
public function update(Request $request, Quiz $quiz)
{
$request->validate([
'Title' => 'required|max:100',
'Description' => 'nullable',
'CreatedBy' => 'required|exists:users,User Id',
]);
$quiz->update($request->all());
return redirect()->route('quizzes.index')->with('success', 'Quiz updated successfully.');
}
public function destroy(Quiz $quiz)
{
$quiz->delete();
return redirect()->route('quizzes.index')->with('success', 'Quiz deleted successfully.');
}
}

4. QuestionController

// app/Http/Controllers/QuestionController.php


namespace App\Http\Controllers;
use App\Models\Question;
use App\Models\Quiz;
use Illuminate\Http\Request;
class QuestionController extends Controller
{
public function index()
{
$questions = Question::all();
return view('questions.index', compact('questions'));
}
public function create()
{
$quizzes = Quiz::all();
return view('questions.create', compact('quizzes'));
}
public function store(Request $request)
{
$request->validate([
'QuizId' => 'required|exists:quizzes,QuizId',
'QuestionText' => 'required',
]);
Question::create($request->all());
return redirect()->route('questions.index')->with('success', 'Question created successfully.');
}
public function show(Question $question)
{
return view('questions.show', compact('question'));
}
public function edit(Question $question)
{
$quizzes = Quiz::all();
return view('questions.edit', compact('question', 'quizzes'));
}
public function update(Request $request, Question $question)
{
$request->validate([
'QuizId' => 'required|exists:quizzes,QuizId',
'QuestionText' => 'required',
]);
$question->update($request->all());
return redirect()->route('questions.index')->with('success', 'Question updated successfully.');
}
public function destroy(Question $question)
{
$question->delete();
return redirect()->route('questions.index')->with('success', 'Question deleted successfully.');
}
}

5. AnswerController

// app/Http/Controllers/AnswerController.php


namespace App\Http\Controllers;
use App\Models\Answer;
use App\Models\Question;
use Illuminate\Http\Request;
class AnswerController extends Controller
{
public function index()
{
$answers = Answer::all();
return view('answers.index', compact('answers'));
}
public function create()
{
$questions = Question::all();
return view('answers.create', compact('questions'));
}
public function store(Request $request)
{
$request->validate([
'QuestionId' => 'required|exists:questions,QuestionId',
'AnswerText' => 'required',
'IsCorrect' => 'required|boolean',
]);
Answer::create($request->all());
return redirect()->route('answers.index')->with('success', 'Answer created successfully.');
}
public function show(Answer $answer)
{
return view('answers.show', compact('answer'));
}
public function edit(Answer $answer)
{
$questions = Question::all();
return view('answers.edit', compact('answer', 'questions'));
}
public function update(Request $request, Answer $answer)
{
$request->validate([
'QuestionId' => 'required|exists:questions,QuestionId',
'AnswerText' => 'required',
'IsCorrect' => 'required|boolean',
]);
$answer->update($request->all());
return redirect()->route('answers.index')->with('success', 'Answer updated successfully.');
}
public function destroy(Answer $answer)
{
$answer->delete();
return redirect()->route('answers.index')->with('success', 'Answer deleted successfully.');
}
}

6. ScoreController

// app/Http/Controllers/ScoreController.php


namespace App\Http\Controllers;
use App\Models\Score;
use App\Models\User;
use App\Models\Quiz;
use Illuminate\Http\Request;
class ScoreController extends Controller
{
public function index()
{
$scores = Score::all();
return view('scores.index', compact('scores'));
}
public function create()
{
$users = User::all();
$quizzes = Quiz::all();
return view('scores.create', compact('users', 'quizzes'));
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'QuizId' => 'required|exists:quizzes,QuizId',
'Score' => 'required|integer',
]);
Score::create($request->all());
return redirect()->route('scores.index')->with('success', 'Score created successfully.');
}
public function show(Score $score)
{
return view('scores.show', compact('score'));
}
public function edit(Score $score)
{
$users = User::all();
$quizzes = Quiz::all();
return view('scores.edit', compact('score', 'users', 'quizzes'));
}
public function update(Request $request, Score $score)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'QuizId' => 'required|exists:quizzes,QuizId',
'Score' => 'required|integer',
]);
$score->update($request->all());
return redirect()->route('scores.index')->with('success', 'Score updated successfully.');
}
public function destroy(Score $score)
{
$score->delete();
return redirect()->route('scores.index')->with('success', 'Score deleted successfully.');
}
}

7. PerformanceController

// app/Http/Controllers/PerformanceController.php


namespace App\Http\Controllers;
use App\Models\Performance;
use App\Models\User;
use Illuminate\Http\Request;
class PerformanceController extends Controller
{
public function index()
{
$performances = Performance::all();
return view('performances.index', compact('performances'));
}
public function create()
{
$users = User::all();
return view('performances.create', compact('users'));
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'TotalQuizzes' => 'required|integer',
'TotalScore' => 'required|integer',
'AverageScore' => 'required|numeric',
]);
Performance::create($request->all());
return redirect()->route('performances.index')->with('success', 'Performance created successfully.');
}
public function show(Performance $performance)
{
return view('performances.show', compact('performance'));
}
public function edit(Performance $performance)
{
$users = User::all();
return view('performances.edit', compact('performance', 'users'));
}
public function update(Request $request, Performance $performance)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'TotalQuizzes' => 'required|integer',
'TotalScore' => 'required|integer',
'AverageScore' => 'required|numeric',
]);
$performance->update($request->all());
return redirect()->route('performances.index')->with('success', 'Performance updated successfully.');
}
public function destroy(Performance $performance)
{
$performance->delete();
return redirect()->route('performances.index')->with('success', 'Performance deleted successfully.');
}
}

8. NotificationController

// app/Http/Controllers/NotificationController.php


namespace App\Http\Controllers;
use App\Models\Notification;
use App\Models\User;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
public function index()
{
$notifications = Notification::all();
return view('notifications.index', compact('notifications'));
}
public function create()
{
$users = User::all();
return view('notifications.create', compact('users'));
}
public function store(Request $request)
{
$ request->validate([
'User Id' => 'required|exists:users,User Id',
'Message' => 'required|string|max:256',
'IsRead' => 'boolean',
]);
Notification::create($request->all());
return redirect()->route('notifications.index')->with('success', 'Notification created successfully.');
}
public function show(Notification $notification)
{
return view('notifications.show', compact('notification'));
}
public function edit(Notification $notification)
{
$users = User::all();
return view('notifications.edit', compact('notification', 'users'));
}
public function update(Request $request, Notification $notification)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'Message' => 'required|string|max:256',
'IsRead' => 'boolean',
]);
$notification->update($request->all());
return redirect()->route('notifications.index')->with('success', 'Notification updated successfully.');
}
public function destroy(Notification $notification)
{
$notification->delete();
return redirect()->route('notifications.index')->with('success', 'Notification deleted successfully.');
}
}

9. AchievementController

// app/Http/Controllers/AchievementController.php


namespace App\Http\Controllers;
use App\Models\Achievement;
use App\Models\User;
use Illuminate\Http\Request;
class AchievementController extends Controller
{
public function index()
{
$achievements = Achievement::all();
return view('achievements.index', compact('achievements'));
}
public function create()
{
$users = User::all();
return view('achievements.create', compact('users'));
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'Title' => 'required|string|max:100',
'Description' => 'nullable|string',
]);
Achievement::create($request->all());
return redirect()->route('achievements.index')->with('success', 'Achievement created successfully.');
}
public function show(Achievement $achievement)
{
return view('achievements.show', compact('achievement'));
}
public function edit(Achievement $achievement)
{
$users = User::all();
return view('achievements.edit', compact('achievement', 'users'));
}
public function update(Request $request, Achievement $achievement)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'Title' => 'required|string|max:100',
'Description' => 'nullable|string',
]);
$achievement->update($request->all());
return redirect()->route('achievements.index')->with('success', 'Achievement updated successfully.');
}
public function destroy(Achievement $achievement)
{
$achievement->delete();
return redirect()->route('achievements.index')->with('success', 'Achievement deleted successfully.');
}
}

Step 3: Create Views

For each controller, you will need to create views for the CRUD operations. The views should be placed in the resources/views directory, organized by model. Here's a basic structure for the views:


resources/views/users/index.blade.php
resources/views/users/create.blade.php
resources/views/users/edit.blade.php
resources/views/users/show.blade.php
resources/views/roles/index.blade.php
resources/views/roles/create.blade.php
resources/views/roles/edit.blade.php
resources/views/roles/show.blade.php
resources/views/quizzes/index.blade.php
resources/views/quizzes/create.blade.php
resources/views/quizzes/edit.blade.php
resources/views/quizzes/show.blade.php
resources/views/questions/index.blade.php
resources/views/questions/create.blade.php
resources/views/questions/edit.blade.php
resources/views/questions/show.blade.php
resources/views/answers/index.blade.php
resources/views/answers/create.blade.php
resources/views/answers/edit.blade.php
resources/views/answers/show.blade.php
resources/views/scores/index.blade.php
resources/views/scores/create.blade.php
resources/views/scores/edit.blade.php
resources/views/scores/show.blade.php
resources/views/performances/index.blade.php
resources/views/performances/create.blade.php
resources/views/performances/edit.blade.php
resources/views/performances/show.blade.php
resources/views/notifications/index.blade.php

Example View Files for Each Controller

1. User Views

resources/views/users/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Users</h1>
<a href="{{ route('users.create') }}" class="btn btn-primary mb-3">Create User</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{ $user->Username }}</td>
<td>{{ $user->Email }}</td>
<td>{{ $user->roles->RoleName ?? 'N/A' }}</td>
<td>
<a href="{{ route('users.edit', $user) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('users.destroy', $user) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('users.show', $user) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/users/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create User</h1>
<form action="{{ route('users.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Username" class="form-label">Username</label>
<input type="text" class="form-control" id="Username" name="Username" required>
</div>
<div class="mb-3">
<label for="PasswordHash" class="form-label">Password</label>
<input type="password" class="form-control" id="PasswordHash" name="PasswordHash" required>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type="email" class="form-control" id="Email" name="Email" required>
</div>
<div class="mb-3">
<label for="RoleId" class="form-label">Role</label>
<select class="form-select" id="RoleId" name="RoleId">
<option value="">Select Role</option>
@foreach($roles as $role)
<option value="{{ $role->RoleId }}">{{ $role->RoleName }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create User</button>
</form>
</div>
@endsection

resources/views/users/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit User</h1>
<form action="{{ route('users.update', $user) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Username" class="form-label">Username</label>
<input type="text" class="form-control" id="Username" name="Username" value="{{ $user->Username }}" required>
</div>
<div class="mb-3">
<label for="PasswordHash" class="form-label">Password</label>
<input type="password" class="form-control" id="PasswordHash" name="PasswordHash" required>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type ="email" class="form-control" id="Email" name="Email" value="{{ $user->Email }}" required>
</div>
<div class="mb-3">
<label for="RoleId" class="form-label">Role</label>
<select class="form-select" id="RoleId" name="RoleId">
<option value="">Select Role</option>
@foreach($roles as $role)
<option value="{{ $role->RoleId }}" {{ $user->RoleId == $role->RoleId ? 'selected' : '' }}>{{ $role->RoleName }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Update User</button>
</form>
</div>
@endsection

resources/views/users/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>User Details</h1>
<p><strong>Username:</strong> {{ $user->Username }}</p>
<p><strong>Email:</strong> {{ $user->Email }}</p>
<p><strong>Role:</strong> {{ $user->roles->RoleName ?? 'N/A' }}</p>
<a href="{{ route('users.index') }}" class="btn btn-secondary">Back to Users</a>
</div>
@endsection

2. Role Views

resources/views/roles/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Roles</h1>
<a href="{{ route('roles.create') }}" class="btn btn-primary mb-3">Create Role</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Role Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($roles as $role)
<tr>
<td>{{ $role->RoleName }}</td>
<td>
<a href="{{ route('roles.edit', $role) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('roles.destroy', $role) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('roles.show', $role) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/roles/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Role</h1>
<form action="{{ route('roles.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="RoleName" class="form-label">Role Name</label>
<input type="text" class="form-control" id="RoleName" name="RoleName" required>
</div>
<button type="submit" class="btn btn-primary">Create Role</button>
</form>
</div>
@endsection

resources/views/roles/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Role</h1>
<form action="{{ route('roles.update', $role) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="RoleName" class="form-label">Role Name</label>
<input type="text" class="form-control" id="RoleName" name="RoleName" value="{{ $role->RoleName }}" required>
</div>
<button type="submit" class="btn btn-primary">Update Role</button>
</form>
</div>
@endsection

resources/views/roles/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Role Details</h1>
<p><strong>Role Name:</strong> {{ $role->RoleName }}</p>
<a href="{{ route('roles.index') }}" class="btn btn-secondary">Back to Roles</a>
</div>
@endsection

3. Quiz Views

resources/views/quizzes/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
< h1>Quizzes</h1>
<a href="{{ route('quizzes.create') }}" class="btn btn-primary mb-3">Create Quiz</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Created By</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($quizzes as $quiz)
<tr>
<td>{{ $quiz->Title }}</td>
<td>{{ $quiz->Description }}</td>
<td>{{ $quiz->user->Username ?? 'N/A' }}</td>
<td>
<a href="{{ route('quizzes.edit', $quiz) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('quizzes.destroy', $quiz) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('quizzes.show', $quiz) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/quizzes/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Quiz</h1>
<form action="{{ route('quizzes.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Title" class="form-label">Title</label>
<input type="text" class="form-control" id="Title" name="Title" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description"></textarea>
</div>
<div class="mb-3">
<label for="CreatedBy" class="form-label">Created By</label>
<select class="form-select" id="CreatedBy" name="CreatedBy" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create Quiz</button>
</form>
</div>
@endsection

resources/views/quizzes/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Quiz</h1>
<form action="{{ route('quizzes.update', $quiz) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Title" class="form-label">Title</label>
<input type="text" class="form-control" id="Title" name="Title" value="{{ $quiz->Title }}" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description">{{ $quiz->Description }}</textarea>
</div>
<div class="mb-3">
<label for="CreatedBy" class="form-label">Created By</label>
<select class="form-select" id="CreatedBy" name="CreatedBy" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}" {{ $quiz->CreatedBy == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Update Quiz</button>
</form>
</div>
@endsection

resources/views/quizzes/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Quiz Details</h1>
<p><strong>Title:</strong> {{ $quiz->Title }}</p>
<p><strong>Description:</strong> {{ $quiz->Description }}</p>
<p><strong>Created By:</strong> {{ $quiz->user->Username ?? 'N/A' }}</p>
<a href="{{ route('quizzes.index ') }}" class="btn btn-secondary">Back to Quizzes</a>
</div>
@endsection

4. Question Views

resources/views/questions/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Questions</h1>
<a href="{{ route('questions.create') }}" class="btn btn-primary mb-3">Create Question</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Question Text</th>
<th>Quiz</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($questions as $question)
<tr>
<td>{{ $question->QuestionText }}</td>
<td>{{ $question->quiz->Title ?? 'N/A' }}</td>
<td>
<a href="{{ route('questions.edit', $question) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('questions.destroy', $question) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('questions.show', $question) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/questions/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Question</h1>
<form action="{{ route('questions.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="QuestionText" class="form-label">Question Text</label>
<input type="text" class="form-control" id="QuestionText" name="QuestionText" required>
</div>
<div class="mb-3">
<label for="QuizId" class="form-label">Quiz</label>
<select class="form-select" id="QuizId" name="QuizId" required>
<option value="">Select Quiz</option>
@foreach($quizzes as $quiz)
<option value="{{ $quiz->QuizId }}">{{ $quiz->Title }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create Question</button>
</form>
</div>
@endsection

resources/views/questions/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Question</h1>
<form action="{{ route('questions.update', $question) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="QuestionText" class="form-label">Question Text</label>
<input type="text" class="form-control" id="QuestionText" name="QuestionText" value="{{ $question->QuestionText }}" required>
</div>
<div class="mb-3">
<label for="QuizId" class="form-label">Quiz</label>
<select class="form-select" id="QuizId" name="QuizId" required>
<option value="">Select Quiz</option>
@foreach($quizzes as $quiz)
<option value="{{ $quiz->QuizId }}" {{ $question->QuizId == $quiz->QuizId ? 'selected' : '' }}>{{ $quiz->Title }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Update Question</button>
</form>
</div>
@endsection

resources/views/questions/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Question Details</h1>
<p><strong>Question Text:</strong> {{ $question->QuestionText }}</p>
<p><strong>Quiz:</strong> {{ $question->quiz->Title ?? 'N/A' }}</p>
<a href="{{ route('questions.index') }}" class="btn btn-secondary">Back to Questions</a>
</div>
@endsection

5. Answer Views

resources/views/answers/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Answers</h1>
<a href="{{ route('answers.create') }}" class="btn btn-primary mb-3">Create Answer</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Answer Text</th>
<th>Question</th>
<th>Is Correct</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($answers as $answer)
<tr>
<td>{{ $answer->AnswerText }}</td>
<td>{{ $answer->question->QuestionText ?? 'N/A' }}</td>
<td>{{ $answer->IsCorrect ? 'Yes' : 'No' }}</td>
<td>
<a href="{{ route('answers.edit', $answer) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('answers.destroy', $answer) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('answers.show', $answer) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/answers/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Answer</h1>
<form action="{{ route('answers.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="AnswerText" class="form-label">Answer Text</label>
<input type="text" class="form-control" id="AnswerText" name="AnswerText" required>
</div>
<div class="mb-3">
<label for="QuestionId" class="form-label">Question</label>
<select class="form-select" id="QuestionId" name="QuestionId" required>
<option value="">Select Question</option>
@foreach($questions as $question)
<option value="{{ $question->QuestionId }}">{{ $question->QuestionText }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="IsCorrect" class="form-label">Is Correct</label>
<select class="form-select" id="IsCorrect" name="IsCorrect" required>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Create Answer</button>
</form>
</div>
@endsection

resources/views/answers/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Answer</h1>
<form action="{{ route('answers.update', $answer) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="AnswerText" class="form-label">Answer Text</label>
<input type="text" class="form-control" id="AnswerText" name="AnswerText" value="{{ $answer->AnswerText }}" required>
</div>
<div class="mb-3">
<label for="QuestionId" class="form-label">Question</label>
<select class="form-select" id="QuestionId" name="QuestionId" required>
<option value="">Select Question</option>
@foreach($questions as $question)
<option value="{{ $question->QuestionId }}" {{ $answer->QuestionId == $question->QuestionId ? 'selected' : '' }}>{{ $question->QuestionText }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="IsCorrect" class="form-label">Is Correct</label>
<select class="form-select" id="IsCorrect" name="IsCorrect" required>
<option value="1" {{ $answer->IsCorrect ? 'selected' : '' }}>Yes</option>
<option value="0" {{ !$answer->IsCorrect ? 'selected' : '' }}>No</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Update Answer</button>
</form>
</div>
@endsection

resources/views/answers/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h 1>Answer Details</h1>
<p><strong>Answer Text:</strong> {{ $answer->AnswerText }}</p>
<p><strong>Question:</strong> {{ $answer->question->QuestionText ?? 'N/A' }}</p>
<p><strong>Is Correct:</strong> {{ $answer->IsCorrect ? 'Yes' : 'No' }}</p>
<a href="{{ route('answers.index') }}" class="btn btn-secondary">Back to Answers</a>
</div>
@endsection

6. Score Views

resources/views/scores/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Scores</h1>
<a href="{{ route('scores.create') }}" class="btn btn-primary mb-3">Create Score</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Quiz</th>
<th>Score</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($scores as $score)
<tr>
<td>{{ $score->user->Username ?? 'N/A' }}</td>
<td>{{ $score->quiz->Title ?? 'N/A' }}</td>
<td>{{ $score->Score }}</td>
<td>
<a href="{{ route('scores.edit', $score) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('scores.destroy', $score) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('scores.show', $score) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/scores/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Score</h1>
<form action="{{ route('scores.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="QuizId" class="form-label">Quiz</label>
<select class="form-select" id="QuizId" name="QuizId" required>
<option value="">Select Quiz</option>
@foreach($quizzes as $quiz)
<option value="{{ $quiz->QuizId }}">{{ $quiz->Title }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Score" class="form-label">Score</label>
<input type="number" class="form-control" id="Score" name="Score" required>
</div>
<button type="submit" class="btn btn-primary">Create Score</button>
</form>
</div>
@endsection

resources/views/scores/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Score</h1>
<form action="{{ route('scores.update', $score) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}" {{ $score->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="QuizId" class="form-label">Quiz</label>
<select class="form-select" id="QuizId" name="QuizId" required>
<option value="">Select Quiz</option @foreach($quizzes as $quiz)
<option value="{{ $quiz->QuizId }}" {{ $score->QuizId == $quiz->QuizId ? 'selected' : '' }}>{{ $quiz->Title }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Score" class="form-label">Score</label>
<input type="number" class="form-control" id="Score" name="Score" value="{{ $score->Score }}" required>
</div>
<button type="submit" class="btn btn-primary">Update Score</button>
</form>
</div>
@endsection

resources/views/scores/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Score Details</h1>
<p><strong>User:</strong> {{ $score->user->Username ?? 'N/A' }}</p>
<p><strong>Quiz:</strong> {{ $score->quiz->Title ?? 'N/A' }}</p>
<p><strong>Score:</strong> {{ $score->Score }}</p>
<a href="{{ route('scores.index') }}" class="btn btn-secondary">Back to Scores</a>
</div>
@endsection

7. Performance Views

resources/views/performances/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Performances</h1>
<a href="{{ route('performances.create') }}" class="btn btn-primary mb-3">Create Performance</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Total Quizzes</th>
<th>Total Score</th>
<th>Average Score</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($performances as $performance)
<tr>
<td>{{ $performance->user->Username ?? 'N/A' }}</td>
<td>{{ $performance->TotalQuizzes }}</td>
<td>{{ $performance->TotalScore }}</td>
<td>{{ $performance->AverageScore }}</td>
<td>
<a href="{{ route('performances.edit', $performance) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('performances.destroy', $performance) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('performances.show', $performance) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/performances/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Performance</h1>
<form action="{{ route('performances.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="TotalQuizzes" class="form-label">Total Quizzes</label>
<input type="number" class="form-control" id="TotalQuizzes" name="TotalQuizzes" required>
</div>
<div class="mb-3">
<label for="TotalScore" class="form-label">Total Score</label>
<input type="number" class="form-control" id="TotalScore" name="TotalScore" required>
</div>
<div class="mb-3">
<label for="AverageScore" class="form-label">Average Score</label>
<input type="number" step="0.01" class="form-control" id="AverageScore" name="AverageScore" required>
</div>
<button type="submit" class="btn btn-primary">Create Performance</button>
</form>
</div>
@endsection

resources/views/performances/edit .blade.php


@extends('layouts.app')
@section('content')
<div class="container"> <h1>Edit Performance</h1> <form action="{{ route('performances.update', $performance) }}" method="POST"> @csrf @method('PUT') <div class="mb-3"> <label for="User Id" class="form-label">User </label> <select class="form-select" id="User Id" name="User Id" required> <option value="">Select User</option> @foreach($users as $user) <option value="{{ $user->User Id }}" {{ $performance->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option> @endforeach </select> </div> <div class="mb-3"> <label for="TotalQuizzes" class="form-label">Total Quizzes</label> <input type="number" class="form-control" id="TotalQuizzes" name="TotalQuizzes" value="{{ $performance->TotalQuizzes }}" required> </div> <div class="mb-3"> <label for="TotalScore" class="form-label">Total Score</label> <input type="number" class="form-control" id="TotalScore" name="TotalScore" value="{{ $performance->TotalScore }}" required> </div> <div class="mb-3"> <label for="AverageScore" class="form-label">Average Score</label> <input type="number" step="0.01" class="form-control" id="AverageScore" name="AverageScore" value="{{ $performance->AverageScore }}" required> </div> <button type="submit" class="btn btn-primary">Update Performance</button> </form> </div>
@endsection

resources/views/performances/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Performance Details</h1>
<p><strong>User:</strong> {{ $performance->user->Username ?? 'N/A' }}</p>
<p><strong>Total Quizzes:</strong> {{ $performance->TotalQuizzes }}</p>
<p><strong>Total Score:</strong> {{ $performance->TotalScore }}</p>
<p><strong>Average Score:</strong> {{ $performance->AverageScore }}</p>
<a href="{{ route('performances.index') }}" class="btn btn-secondary">Back to Performances</a>
</div>
@endsection

8. Notification Views

resources/views/notifications/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Notifications</h1>
<a href="{{ route('notifications.create') }}" class="btn btn-primary mb-3">Create Notification</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Message</th>
<th>Is Read</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($notifications as $notification)
<tr>
<td>{{ $notification->user->Username ?? 'N/A' }}</td>
<td>{{ $notification->Message }}</td>
<td>{{ $notification->IsRead ? 'Yes' : 'No' }}</td>
<td>
<a href="{{ route('notifications.edit', $notification) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('notifications.destroy', $notification) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('notifications.show', $notification) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/notifications/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Notification</h1>
<form action="{{ route('notifications.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Message" class="form-label">Message</label>
<textarea class="form-control" id="Message" name="Message" required></textarea>
</div>
<div class="mb-3">
<label for="IsRead" class="form-label">Is Read</label>
<select class="form-select" id="IsRead" name="IsRead" required>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Create Notification</button>
</form>
</div>
@endsection

resources/views/notifications/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Notification</h1>
<form action="{{ route('notifications.update', $notification) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}" {{ $notification->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Message" class="form-label">Message</label>
<textarea class="form-control" id="Message" name="Message" required>{{ $notification->Message }}</textarea>
</div>
<div class="mb-3">
<label for="IsRead" class="form-label">Is Read</label>
<select class="form-select" id="IsRead" name="IsRead" required>
<option value="1" {{ $notification->IsRead ? 'selected' : '' }}>Yes</option>
<option value="0" {{ !$notification->IsRead ? 'selected' : '' }}>No</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Update Notification</button>
</form>
</div>
@endsection

resources/views/notifications/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Notification Details</h1>
<p><strong>User:</strong> {{ $notification->user->Username ?? 'N/A' }}</p>
<p><strong>Message:</strong> {{ $notification->Message }}</p>
<p><strong>Is Read:</strong> {{ $notification->IsRead ? 'Yes' : 'No' }}</p>
<a href="{{ route('notifications.index') }}" class="btn btn-secondary">Back to Notifications</a>
</div>
@endsection

9. Achievement Views

resources/views/achievements/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Achievements</h1>
<a href="{{ route('achievements.create') }}" class="btn btn-primary mb-3">Create Achievement</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Title</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($achievements as $achievement)
<tr>
<td>{{ $achievement->user->Username ?? 'N/A' }}</td>
<td>{{ $achievement->Title }}</td>
<td>{{ $achievement->Description }}</td>
<td>
<a href="{{ route('achievements.edit', $achievement) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('achievements.destroy', $achievement) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('achievements.show', $ achievement) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/achievements/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Achievement</h1>
<form action="{{ route('achievements.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Title" class="form-label">Title</label>
<input type="text" class="form-control" id="Title" name="Title" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description"></textarea>
</div>
<button type="submit" class="btn btn-primary">Create Achievement</button>
</form>
</div>
@endsection

resources/views/achievements/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Achievement</h1>
<form action="{{ route('achievements.update', $achievement) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id" required>
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}" {{ $achievement->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Title" class="form-label">Title</label>
<input type="text" class="form-control" id="Title" name="Title" value="{{ $achievement->Title }}" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description">{{ $achievement->Description }}</textarea>
</div>
<button type="submit" class="btn btn-primary">Update Achievement</button>
</form>
</div>
@endsection

resources/views/achievements/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Achievement Details</h1>
<p><strong>User:</strong> {{ $achievement->user->Username ?? 'N/A' }}</p>
<p><strong>Title:</strong> {{ $achievement->Title }}</p>
<p><strong>Description:</strong> {{ $achievement->Description }}</p>
<a href="{{ route('achievements.index') }}" class="btn btn-secondary">Back to Achievements</a>
</div>
@endsection

Creating a layout file in Laravel allows you to define a common structure for your views, which can include headers, footers, and navigation menus.

Below is an example of a layout file using Bootstrap 5, which you can place in the resources/views/layouts directory.

Step 1: Create the Layout File

Create a new file named app.blade.php in the resources/views/layouts directory.

resources/views/layouts/app.blade.php


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@yield('title', 'My Application')</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="{{ asset('css/app.css') }}"> <!-- Optional custom CSS -->
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="{{ url('/') }}">My Application</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{{ route('users.index') }}">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('roles.index') }}">Roles</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('quizzes.index') }}">Quizzes</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('questions.index') }}">Questions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('answers.index') }}">Answers</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('scores.index') }}">Scores</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('performances.index') }}">Performances</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('notifications.index') }}">Notifications</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('achievements.index') }}">Achievements</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
@yield('content')
</div>
<footer class="bg-light text-center text-lg-start mt-4">
<div class="text-center p-3">
© 2023 My Application
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Modify User Index View


@extends('layouts.app')
@section('title', 'Users')
@section('content')
<div class="container">
<h1>Users</h1>
<a href="{{ route('users.create') }}" class="btn btn-primary mb-3">Create User</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{ $user->Username }}</td>
<td>{{ $user->Email }}</td>
<td>{{ $user->roles->RoleName ?? 'N/A' }}</td>
<td>
<a href="{{ route('users.edit', $user) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('users.destroy', $user) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('users.show', $user) }}" class="btn btn-info">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

To create a dashboard page in your Laravel application that displays consolidated data related to your project, you can follow these steps:

Step 1: Create a Route for the Dashboard

Add a route for the dashboard in your routes/web.php file:


use App\Http\Controllers\DashboardController;
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

Step 2: Create a Controller Method to Fetch Data

Create a new controller named DashboardController if you haven't already:


php artisan make:controller DashboardController

Then, implement the index method to fetch the consolidated data:

app/Http/Controllers/DashboardController.php


namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Role;
use App\Models\Quiz;
use App\Models\Question;
use App\Models\Answer;
use App\Models\Score;
use App\Models\Performance;
use App\Models\Notification;
use App\Models\Achievement;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function index()
{
$userCount = User::count();
$roleCount = Role::count();
$quizCount = Quiz::count();
$questionCount = Question::count();
$answerCount = Answer::count();
$scoreCount = Score::count();
$performanceCount = Performance::count();
$notificationCount = Notification::count();
$achievementCount = Achievement::count();
return view('dashboard.index', compact(
'userCount',
'roleCount',
'quizCount',
'questionCount',
'answerCount',
'scoreCount',
'performanceCount',
'notificationCount',
'achievementCount'
));
}
}

Step 3: Create a Dashboard View

Create a new view file for the dashboard in resources/views/dashboard/index.blade.php:


@extends('layouts.app')
@section('title', 'Dashboard')
@section('content')
<div class="container">
<h1>Dashboard</h1>
<div class="row">
<div class="col-md-4">
<div class="card text-white bg-primary mb-3">
<div class="card-header">Total Users</div>
<div class="card-body">
<h5 class="card-title">{{ $userCount }}</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-success mb-3">
<div class="card-header">Total Roles</div>
<div class="card-body">
<h5 class="card-title">{{ $roleCount }}</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-info mb-3">
<div class="card-header">Total Quizzes</div>
<div class="card-body">
<h5 class="card-title">{{ $quizCount }}</h5>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="card text-white bg-warning mb-3">
<div class="card-header">Total Questions</div>
<div class="card-body">
<h5 class="card-title">{{ $questionCount }}</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-danger mb-3">
<div class="card-header">Total Answers</div>
<div class="card-body">
<h5 class="card-title">{{ $answerCount }}</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-secondary mb-3">
<div class="card-header">Total Scores</div>
<div class="card-body">
<h5 class="card-title">{{ $scoreCount }}</h5>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="card text-white bg-dark mb-3">
<div class="card-header">Total Performances</div>
<div class="card-body">
<h5 class="card-title">{{ $performanceCount }}</h5>
</div>
</div>
</div <div class="col-md-4">
<div class="card text-white bg-light mb-3">
<div class="card-header">Total Notifications</div>
<div class="card-body">
<h5 class="card-title">{{ $notificationCount }}</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-primary mb-3">
<div class="card-header">Total Achievements</div>
<div class="card-body">
<h5 class="card-title">{{ $achievementCount }}</h5>
</div>
</div>
</div>
</div>
</div>
@endsection

Step 4: Add a Link to the Dashboard in the Navigation

To make the dashboard accessible, add a link to it in your navigation menu within the layout file:


<li class="nav-item">
<a class="nav-link" href="{{ route('dashboard') }}">Dashboard</a>
</li>

This setup will create a dashboard page that displays consolidated data related to your project, providing a quick overview of key metrics. You can further customize the dashboard by adding charts or additional data visualizations as needed.