feat: add bylaw management features including documents, legal authorities, subject categories, and nodes
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BylawSubjectCategory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BylawSubjectCategoryController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = BylawSubjectCategory::query();
|
||||
if ($request->filled('q')) {
|
||||
$query->where('name', 'like', "%{$request->q}%");
|
||||
} $items = $query->latest()->paginate(15)->withQueryString();
|
||||
|
||||
return view('admin.bylaw-subject-category.index', compact('items'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$parents = BylawSubjectCategory::all();
|
||||
|
||||
return view('admin.bylaw-subject-category.create', compact('parents'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate(['parent_id' => 'nullable|exists:bylaw_subject_categories,id', 'name' => 'required|string', 'slug' => 'nullable|string|unique:bylaw_subject_categories,slug', 'sort_order' => 'nullable|integer']);
|
||||
$data['slug'] = $data['slug'] ?? Str::slug($data['name']);
|
||||
BylawSubjectCategory::create($data);
|
||||
|
||||
return redirect(route('bylaw-subject-category.index'));
|
||||
}
|
||||
|
||||
public function edit(BylawSubjectCategory $bylawSubjectCategory)
|
||||
{
|
||||
$parents = BylawSubjectCategory::where('id', '!=', $bylawSubjectCategory->id)->get();
|
||||
|
||||
return view('admin.bylaw-subject-category.update', compact('bylawSubjectCategory', 'parents'));
|
||||
}
|
||||
|
||||
public function show(BylawSubjectCategory $bylawSubjectCategory)
|
||||
{
|
||||
return redirect(route('bylaw-subject-category.edit', $bylawSubjectCategory));
|
||||
}
|
||||
|
||||
public function update(Request $request, BylawSubjectCategory $bylawSubjectCategory)
|
||||
{
|
||||
$data = $request->validate(['parent_id' => 'nullable|exists:bylaw_subject_categories,id', 'name' => 'required|string', 'slug' => 'required|string|unique:bylaw_subject_categories,slug,'.$bylawSubjectCategory->id, 'sort_order' => 'nullable|integer']);
|
||||
$bylawSubjectCategory->update($data);
|
||||
|
||||
return redirect(route('bylaw-subject-category.edit', $bylawSubjectCategory));
|
||||
}
|
||||
|
||||
public function destroy(BylawSubjectCategory $bylawSubjectCategory)
|
||||
{
|
||||
$bylawSubjectCategory->delete();
|
||||
|
||||
return redirect(route('bylaw-subject-category.index'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user