A comprehensive Laravel-based quiz management system with AI-powered quiz generation capabilities.
This backend provides the API endpoints used by the Quiz App Flutter project:
- Repository: https://github.com/mohitj2401/Quiz_app
- 🎯 Quiz Management (Create, Edit, Delete)
- 📝 Question Management with Multiple Choice Options
- 👥 User Management with Role-Based Permissions
- 📊 Subject Management
- 📈 Quiz Results & Analytics
- 🔐 Authentication & Authorization (Laravel Passport)
- Multiple AI Providers Support:
- OpenAI (GPT-4o-mini) - Cloud-based, high quality
- Ollama (Local) - FREE, no API costs, privacy-focused
- Google Gemini - Cloud-based, cost-effective
- Automatic Question Generation based on topics
- Configurable Difficulty Levels (Easy, Medium, Hard)
- AI Provider Settings UI for easy configuration
- Generate Quiz on Subject Creation option
- PHP >= 8.2
- Composer
- MySQL/MariaDB
- Node.js & NPM (for frontend assets)
- Optional: Ollama (for local AI quiz generation)
git clone <repository-url>
cd quize_beckendV2composer install
npm installcp .env.example .env
php artisan key:generateEdit .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_passwordphp artisan migrate --seedphp artisan passport:installAI_PROVIDER=openai
OPENAI_API_KEY=sk-your-api-key# Install Ollama from https://ollama.ai
ollama pull llama3.1:8bAI_PROVIDER=ollama
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=llama3.1:8bAI_PROVIDER=gemini
GEMINI_API_KEY=your-gemini-api-keyphp artisan serveWhy Ollama?
- ✅ Completely FREE - No API costs
- ✅ Privacy - All data stays local
- ✅ Fast - No network latency
- ✅ No Rate Limits - Generate unlimited quizzes
Installation:
- Download Ollama from https://ollama.ai
- Install and run Ollama
- Pull recommended model:
ollama pull llama3.1:8b
- Configure in Settings UI (
/settings)
Recommended Models:
llama3.1:8b- Best overall quality (Recommended)qwen2.5:7b- Excellent JSON formattingmistral:7b- Fastest inferencegemma2:9b- Best for educational content
OpenAI (Best Quality)
- Get API key: https://platform.openai.com/api-keys
- Cost: ~$0.01-0.02 per 10 questions
Google Gemini (Cost-Effective)
- Get API key: https://makersuite.google.com/app/apikey
- Cost: ~$0.005-0.01 per 10 questions
-
Quiz and question generation now run as background jobs so AI work does not block web requests. Two jobs are used:
GenerateAiQuizJob— creates the quiz record and metadata, uploads image path and enqueues question generation.CreateQuizQuestionsJob— generates questions for a quiz and saves them.
-
Question generation is batched: each
CreateQuizQuestionsJobwill generate up toquestions_batchquestions (default 5) and re-dispatch itself for remaining questions until the requested number is reached. This batch size is configurable (see Config below).
- POST
/generate/quiz/ai— generate entire quiz (quiz + questions) using AI (queued) (namedgenerate.quiz.ai). - POST
/generate/questions/{quiz}/ai— generate questions for an existing quiz using AI (queued) (namedgenerate.question.ai). - GET
/system/batch-jobs— UI to monitor queued and failed jobs (namedsystem.batch-jobs.index). - POST
/system/batch-jobs/{id}/retry— retry a failed job from the UI (namedsystem.batch-jobs.retry).
- Visit
/system/batch-jobsin the admin area to view recent queued jobs and failed jobs. - Failed jobs have a Retry button that will move the failed job back to the queue for re-processing.
- New config file:
config/ai.php(commit added)
return [
// Number of questions to generate per job batch
'questions_batch' => env('AI_QUESTIONS_BATCH', 5),
];- Override the batch size with
.env:AI_QUESTIONS_BATCH=5(default 5).
Make sure your queue worker is running to process AI jobs:
php artisan queue:work- Generated questions follow the project's convention:
option1is always the correct answer. - If you expect large generation jobs, increase worker concurrency or use rate-limiting/delays on job dispatch.
http://localhost:8000/home
- Navigate to
/settings - Select your preferred AI provider
- Enter configuration details
- Test connection
- Save settings
Method 1: Standalone Generation
- Go to "Create Quiz with AI" (
/create/quiz/ai) - Enter topic, difficulty, and number of questions
- Upload quiz image
- Click "Generate Quiz with AI"
Method 2: During Subject Creation
- Go to "Create Subject"
- Enter subject details
- ✅ Check "Generate Quiz & Questions with AI"
- Configure AI settings
- Create subject - Quiz generated automatically!
app/
├── Http/Controllers/
│ └── Web/
│ ├── QuizController.php
│ ├── QuestionController.php
│ ├── SubjectController.php
│ ├── SettingsController.php
│ └── ...
├── Models/
│ ├── Quiz.php
│ ├── Question.php
│ ├── Subject.php
│ ├── Setting.php
│ └── ...
└── Services/AI/
├── AIProviderInterface.php
├── AIServiceFactory.php
├── OpenAIService.php
├── OllamaService.php
└── GeminiService.php
resources/views/
├── admin/
│ ├── quiz-ai-generate.blade.php
│ ├── settings/
│ │ └── index.blade.php
│ └── ...
└── subject/
└── create.blade.php
- Factory Pattern: Automatic provider switching
- Interface-Based: Easy to add new providers
- Settings Management: UI-based configuration
- Test Connection: Verify setup before use
option1
option1= Correct answeroption2,option3,option4= Incorrect options
POST /api/login
POST /api/register
GET /api/quiz/{subject}
GET /api/quiz/{quiz_id}/single
POST /api/result
GET /api/results/{quiz_id}
- Framework: Laravel 11
- Authentication: Laravel Passport
- Permissions: Spatie Laravel Permission
- PDF Generation: DomPDF
- Excel: Maatwebsite Excel
- DataTables: Yajra DataTables
- AI Integration:
- OpenAI PHP Client
- Google Gemini PHP Client
- HTTP Client (for Ollama)
| Provider | 10 Questions | 50 Questions | Quality | Speed |
|---|---|---|---|---|
| Ollama | FREE | FREE | ⭐⭐⭐⭐ | Very Fast |
| Gemini | $0.005-0.01 | $0.025-0.05 | ⭐⭐⭐⭐ | Fast |
| OpenAI | $0.01-0.02 | $0.05-0.10 | ⭐⭐⭐⭐⭐ | Fast |
# Check if Ollama is running
ollama list
# Start Ollama
ollama serve
# Pull model if not available
ollama pull llama3.1:8b# Fresh migration
php artisan migrate:fresh --seed
# Clear cache
php artisan config:clear
php artisan cache:clear# Fix storage permissions
chmod -R 775 storage bootstrap/cache- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is open-sourced software licensed under the MIT license.
For issues and questions, please open an issue on GitHub.
- ✅ Upgraded to Laravel 11
- ✅ Added multi-AI provider support (OpenAI, Ollama, Gemini)
- ✅ Implemented AI quiz generation
- ✅ Added Settings UI for AI configuration
- ✅ Added AI generation option to subject creation
- ✅ Updated dependencies for Laravel 11 compatibility
Made with ❤️ using Laravel