Merge remote-tracking branch 'upstream-local/clean-main' into clean-main

This commit is contained in:
m.razaghi
2026-08-08 17:44:14 +03:30
7 changed files with 358 additions and 188 deletions

View File

@@ -27,23 +27,23 @@ class QuizController extends Controller
public function store(Request $request)
{
// 1. Validate only the text and number fields
$validated = $request->validate([
'title' => 'required|string|max:255',
'category_id' => 'required|exists:quiz_categories,id',
'year' => 'nullable|integer',
'type' => 'required|in:multiple_choice,descriptive,mixed',
'duration_minutes' => 'required|integer|min:1',
'has_negative_score' => 'boolean',
'is_free' => 'boolean',
'is_published' => 'boolean',
'description' => 'nullable|string',
]);
$validated['slug'] = Str::slug($validated['title']) . '-' . time();
// 2. Safely handle checkboxes and generate slug
$validated['slug'] = \Illuminate\Support\Str::slug($validated['title']) . '-' . time();
$validated['has_negative_score'] = $request->has('has_negative_score');
$validated['is_free'] = $request->has('is_free');
$validated['is_published'] = $request->has('is_published');
// 3. Create the quiz
$quiz = Quiz::create($validated);
return redirect()->route('quizzes.questions.index', $quiz->id)

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\QuizSubject;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class QuizSubjectController extends Controller
{
public function index()
{
// Load subjects and count how many questions belong to each
$subjects = QuizSubject::withCount('questions')->latest()->get();
return view('admin.quiz-subjects.index', compact('subjects'));
}
public function store(Request $request)
{
$request->validate([
'title' => 'required|string|max:255',
]);
QuizSubject::create([
'title' => $request->title,
// Generate a unique slug for potential API/URL usage
'slug' => Str::slug($request->title) . '-' . time(),
]);
return back()->with('success', 'درس با موفقیت اضافه شد.');
}
public function destroy(QuizSubject $quiz_subject)
{
// Prevent deletion if questions are already assigned to this subject
if ($quiz_subject->questions()->count() > 0) {
return back()->with('error', 'این درس دارای سوال است و نمی‌تواند حذف شود. ابتدا سوالات مربوطه را ویرایش یا حذف کنید.');
}
$quiz_subject->delete();
return back()->with('success', 'درس با موفقیت حذف شد.');
}
}