The quiz system has been significantly enhanced with advanced features for a comprehensive learning management experience.
allow_multiple_attempts- Enable/disable multiple attemptsmax_attempts- Limit maximum number of attemptsshuffle_questions- Randomize question ordershuffle_answers- Randomize answer optionsshow_correct_answers- Show correct answers after submissionshow_results_immediately- Display results immediately after quizquestions_per_page- Number of questions per pageallow_navigation- Allow back/forward navigationnegative_marking- Enable negative marking for wrong answersnegative_mark_value- Fraction for negative marks (e.g., 0.25 = 25%)status- Draft, Published, or Archivedstart_date- Quiz availability start dateend_date- Quiz availability end daterandom_question_count- Show random subset of questionsrequire_all_questions- Force answering all questionsinstructions- Custom instructions for studentspass_message- Custom message when student passesfail_message- Custom message when student fails
explanation- Explanation for the correct answerdifficulty- Question difficulty level (easy, medium, hard)tags- JSON array of tags for categorizationpartial_points- Partial point allocation
attempt_number- Attempt sequence numbertotal_points- Total possible pointscorrect_answers- Number of correct answersincorrect_answers- Number of incorrect answersunanswered_questions- Number of unanswered questionstime_spent- JSON array tracking time per questionanswers_review- JSON array with detailed answer reviewsubmitted- Whether the attempt has been submitted
Added methods:
canUserAttempt($userId)- Check if user can attempt quizgetUserAttemptNumber($userId)- Get next attempt numberisAvailable()- Check if quiz is currently availablegetQuestionsForAttempt()- Get questions based on settingsgetTotalPointsAttribute()- Calculate total pointsgetUserBestScore($userId)- Get user's best scoregetAverageScoreAttribute()- Calculate average scoregetCompletionRateAttribute()- Calculate completion rategetPassRateAttribute()- Calculate pass rate
- Added fields: explanation, difficulty, tags, partial_points
- Method:
getAnswersForAttempt()- Get answers with shuffling
Added methods:
markAsPassed()- Automatically determine pass statuscalculateCompletionPercentage()- Calculate completion %getDurationAttribute()- Get attempt duration in secondsgetFormattedDurationAttribute()- Get formatted durationisInProgress()- Check if attempt is in progress
Manages quiz questions and answers:
index()- View all questions for a quizcreate()- Create new question formstore()- Save new question with answersedit()- Edit question formupdate()- Update question and answersdestroy()- Delete questionreorder()- Reorder questions
Manages quiz taking experience:
start()- Start a new quiz attemptshow()- Display quiz taking interfacesaveAnswer()- Save user answers (AJAX)submit()- Submit completed quizresult()- Show quiz resultsprogress()- Get progress status (AJAX)calculateScore()- Calculate score with negative marking
- Enhanced
store()andupdate()methods to handle all new fields
// Quiz taking
GET /quizzes/{quiz}/start
GET /quizzes/{quiz}/attempts/{attempt}
POST /quizzes/{quiz}/attempts/{attempt}/save
POST /quizzes/{quiz}/attempts/{attempt}/submit
GET /quizzes/{quiz}/attempts/{attempt}/result
GET /quizzes/{quiz}/attempts/{attempt}/progress
// Question management
GET /quizzes/{quiz}/questions
GET /quizzes/{quiz}/questions/create
POST /quizzes/{quiz}/questions
GET /quizzes/{quiz}/questions/{question}/edit
PUT /quizzes/{quiz}/questions/{question}
DELETE /quizzes/{quiz}/questions/{question}
POST /quizzes/{quiz}/questions/reorder
- Comprehensive form with all advanced settings
- Organized into sections:
- Basic Information
- Assessment Settings
- Attempts Settings
- Display Settings
- Results Settings
- Negative Marking
- Custom Messages
- JavaScript for dynamic field visibility
- Simplified creation form
- Auto-sets sensible defaults
- Can be enhanced in edit form later
- Added "Manage Questions" button
- Shows quiz statistics and attempts
- Control whether students can retake quizzes
- Set maximum attempt limits
- Track attempt numbers
- Preserve best scores
- Randomize question order to prevent copying
- Shuffle answer options for better assessment
- Maintain data integrity
- Standard scoring
- Negative marking for wrong answers
- Partial points support
- Custom scoring formulas per question
- Questions per page pagination
- Navigation controls
- Progress tracking
- Real-time answer saving
- Start/end dates
- Time windows
- Draft/Published/Archived status
- Access control
- Immediate or delayed results
- Show/hide correct answers
- Custom pass/fail messages
- Detailed score breakdown
- Random subset of questions
- Maintains pool of questions
- Fresh experience per attempt
- Time spent per question
- Answer review tracking
- Completion rates
- Pass rates
- Average scores
- User performance history
- Go to lesson page
- Click "Create Quiz"
- Fill in basic information
- Set default status (draft/published)
- Save and edit for advanced settings
- Click "Manage Questions" on quiz
- Add questions with multiple answers
- Mark correct answers
- Add explanations
- Set difficulty and tags
- Find published quiz
- Click "Start Quiz"
- Answer questions (auto-saved)
- Submit when ready
- View results (if enabled)
- Create question management views in
resources/views/quizzes/questions/ - Create quiz taking views in
resources/views/quizzes/taking/ - Add JavaScript for auto-save and timer
- Implement real-time progress tracking
- Add question import/export features
- Create analytics dashboard
Run the following migration:
php artisan migrateThis will add all new fields to existing tables without losing data.
Quiz
├── hasMany QuizQuestion
│ ├── hasMany QuizAnswer
│ └── hasMany UserAnswer
├── hasMany QuizAttempt
│ └── hasMany UserAnswer
└── belongsTo Lesson
└── belongsTo Module
└── belongsTo Course
QuizAttempt
├── belongsTo Quiz
├── belongsTo User
└── hasMany UserAnswer
├── belongsTo QuizQuestion
└── belongsTo QuizAnswer
- Questions are loaded with eager loading
- Answers are cached per attempt
- JSON fields for time tracking (flexible, not searchable)
- Index on user_id + quiz_id for quick lookup
- Batch updates for reordering
- User can only access their own attempts
- Quiz availability validation
- Attempt limit enforcement
- Time limit enforcement
- Can't modify submitted attempts
- Authorization checks on all actions