diff --git a/app/Http/Controllers/Admin/JudicialPrecedentCategoryController.php b/app/Http/Controllers/Admin/JudicialPrecedentCategoryController.php new file mode 100644 index 0000000..97f3b01 --- /dev/null +++ b/app/Http/Controllers/Admin/JudicialPrecedentCategoryController.php @@ -0,0 +1,89 @@ +filled('q')) { + $q = $request->q; + $query->where('name', 'like', "%{$q}%"); + } + + $perPage = min(max((int) $request->input('per_page', 15), 10), 100); + $categories = $query->paginate($perPage)->withQueryString(); + + return view('admin.judicial-precedent-category.index', compact('categories')); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + return view('admin.judicial-precedent-category.create'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + $validated = $request->validate([ + 'name' => 'required|string|unique:judicial_precedent_categories,name' + ]); + + JudicialPrecedentCategory::create($validated); + + return redirect(route('judicial-precedent-category.index')); + } + + /** + * Display the specified resource. + */ + public function show(string $id) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(JudicialPrecedentCategory $judicialPrecedentCategory) + { + return view('admin.judicial-precedent-category.update', compact('judicialPrecedentCategory')); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, JudicialPrecedentCategory $judicialPrecedentCategory) + { + $validated = $request->validate([ + 'name' => 'required|string|unique:judicial_precedent_categories,name,' . $judicialPrecedentCategory->id + ]); + + $judicialPrecedentCategory->update($validated); + + return redirect(route('judicial-precedent-category.edit', $judicialPrecedentCategory->id)); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(JudicialPrecedentCategory $judicialPrecedentCategory) + { + $judicialPrecedentCategory->delete(); + return redirect(route('judicial-precedent-category.index')); + } +} diff --git a/app/Http/Controllers/Admin/JudicialPrecedentController.php b/app/Http/Controllers/Admin/JudicialPrecedentController.php index a27d27d..902ec18 100644 --- a/app/Http/Controllers/Admin/JudicialPrecedentController.php +++ b/app/Http/Controllers/Admin/JudicialPrecedentController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Art; use App\Models\JudicialPrecedent; +use App\Models\JudicialPrecedentCategory; use Illuminate\Http\Request; class JudicialPrecedentController extends Controller @@ -31,7 +32,8 @@ class JudicialPrecedentController extends Controller public function create() { $arts = Art::all(); - return view('admin.judicial-precedent.create', compact('arts')); + $categories = JudicialPrecedentCategory::all(); + return view('admin.judicial-precedent.create', compact('arts', 'categories')); } public function store(Request $request) @@ -42,6 +44,7 @@ class JudicialPrecedentController extends Controller 'subject' => 'required|string', 'full_text' => 'required|string', 'issuing_authority' => 'nullable|string', + 'category_id' => 'nullable|exists:judicial_precedent_categories,id', 'art_ids' => 'nullable|array', 'art_ids.*' => 'exists:arts,id' ]); @@ -51,7 +54,8 @@ class JudicialPrecedentController extends Controller 'ruling_date' => $validated['ruling_date'], 'subject' => $validated['subject'], 'full_text' => $validated['full_text'], - 'issuing_authority' => $validated['issuing_authority'] ?? 'هیأت عمومی دیوان عالی کشور' + 'issuing_authority' => $validated['issuing_authority'] ?? 'هیأت عمومی دیوان عالی کشور', + 'category_id' => $validated['category_id'] ]); if (!empty($validated['art_ids'])) { @@ -64,9 +68,10 @@ class JudicialPrecedentController extends Controller public function edit(JudicialPrecedent $judicialPrecedent) { $arts = Art::all(); + $categories = JudicialPrecedentCategory::all(); $selectedArtIds = $judicialPrecedent->arts->pluck('id')->toArray(); - return view('admin.judicial-precedent.update', compact('judicialPrecedent', 'arts', 'selectedArtIds')); + return view('admin.judicial-precedent.update', compact('judicialPrecedent', 'arts', 'categories', 'selectedArtIds')); } public function update(Request $request, JudicialPrecedent $judicialPrecedent) @@ -77,6 +82,7 @@ class JudicialPrecedentController extends Controller 'subject' => 'required|string', 'full_text' => 'required|string', 'issuing_authority' => 'nullable|string', + 'category_id' => 'nullable|exists:judicial_precedent_categories,id', 'art_ids' => 'nullable|array', 'art_ids.*' => 'exists:arts,id' ]); diff --git a/app/Models/JudicialPrecedent.php b/app/Models/JudicialPrecedent.php index adb1510..306768e 100644 --- a/app/Models/JudicialPrecedent.php +++ b/app/Models/JudicialPrecedent.php @@ -14,7 +14,8 @@ class JudicialPrecedent extends Model 'ruling_date', 'subject', 'full_text', - 'issuing_authority' + 'issuing_authority', + 'category_id' ]; protected $hidden = ['created_at', 'updated_at']; @@ -23,4 +24,9 @@ class JudicialPrecedent extends Model { return $this->belongsToMany(Art::class, 'art_judicial_precedent'); } + + public function category() + { + return $this->belongsTo(JudicialPrecedentCategory::class, 'category_id'); + } } diff --git a/app/Models/JudicialPrecedentCategory.php b/app/Models/JudicialPrecedentCategory.php new file mode 100644 index 0000000..059fbed --- /dev/null +++ b/app/Models/JudicialPrecedentCategory.php @@ -0,0 +1,18 @@ +hasMany(JudicialPrecedent::class, 'category_id'); + } +} diff --git a/database/migrations/2026_05_03_194032_create_judicial_precedent_categories_table.php b/database/migrations/2026_05_03_194032_create_judicial_precedent_categories_table.php new file mode 100644 index 0000000..56868bf --- /dev/null +++ b/database/migrations/2026_05_03_194032_create_judicial_precedent_categories_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('name')->unique()->comment('نام دستهبندی'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('judicial_precedent_categories'); + } +}; diff --git a/database/migrations/2026_05_03_194251_add_category_id_to_judicial_precedents_table.php b/database/migrations/2026_05_03_194251_add_category_id_to_judicial_precedents_table.php new file mode 100644 index 0000000..7ae93cb --- /dev/null +++ b/database/migrations/2026_05_03_194251_add_category_id_to_judicial_precedents_table.php @@ -0,0 +1,29 @@ +foreignId('category_id')->nullable()->constrained('judicial_precedent_categories')->onDelete('set null')->comment('دستهبندی'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('judicial_precedents', function (Blueprint $table) { + $table->dropForeign(['category_id']); + $table->dropColumn('category_id'); + }); + } +}; diff --git a/resources/views/admin/judicial-precedent-category/create.blade.php b/resources/views/admin/judicial-precedent-category/create.blade.php new file mode 100644 index 0000000..b00adb9 --- /dev/null +++ b/resources/views/admin/judicial-precedent-category/create.blade.php @@ -0,0 +1,25 @@ +@extends('admin.layouts.app') +@section('content') +