feat(BylawDocument): enhance bylaw document forms with improved validation and file upload support

This commit is contained in:
2026-06-26 15:59:45 +03:30
parent 9cf6957675
commit f242b8936a
3 changed files with 382 additions and 28 deletions

View File

@@ -7,6 +7,7 @@ use App\Models\BylawDocument;
use App\Models\BylawLegalAuthority;
use App\Models\BylawSubjectCategory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class BylawDocumentController extends Controller
{
@@ -31,7 +32,29 @@ class BylawDocumentController extends Controller
public function store(Request $request)
{
$data = $request->validate(['title' => 'required|string|max:1000', 'category_id' => 'nullable|exists:bylaw_subject_categories,id', 'approval_authority_id' => 'nullable|exists:bylaw_legal_authorities,id', 'approval_date' => 'nullable|date', 'promulgation_authority_id' => 'nullable|exists:bylaw_legal_authorities,id', 'promulgation_date' => 'nullable|date', 'promulgation_number' => 'nullable|string|max:100', 'official_gazette_number' => 'nullable|string|max:100', 'official_gazette_date' => 'nullable|date', 'execution_date' => 'nullable|date', 'bylaw_type' => 'required|in:executive,delegated,independent', 'global_status' => 'required|in:valid,explicitly_repealed,implicitly_repealed,annulled,expired,draft', 'pdf_file_path' => 'nullable|string|max:500', 'is_published' => 'nullable|boolean', 'description' => 'nullable|string']);
$data = $request->validate([
'title' => 'required|string|max:1000',
'category_id' => 'nullable|exists:bylaw_subject_categories,id',
'approval_authority_id' => 'nullable|exists:bylaw_legal_authorities,id',
'approval_date' => 'nullable|date',
'promulgation_authority_id' => 'nullable|exists:bylaw_legal_authorities,id',
'promulgation_date' => 'nullable|date',
'promulgation_number' => 'nullable|string|max:100',
'official_gazette_number' => 'nullable|string|max:100',
'official_gazette_date' => 'nullable|date',
'execution_date' => 'nullable|date',
'bylaw_type' => 'required|in:executive,delegated,independent',
'global_status' => 'required|in:valid,explicitly_repealed,implicitly_repealed,annulled,expired,draft',
'pdf_file' => 'nullable|file|mimes:pdf|max:20480',
'pdf_file_path' => 'nullable|string|max:500',
'is_published' => 'nullable|boolean',
'description' => 'nullable|string',
]);
if ($request->hasFile('pdf_file')) {
$data['pdf_file_path'] = $request->file('pdf_file')->store('pdfs', 'public');
}
$data['is_published'] = $request->boolean('is_published');
BylawDocument::create($data);
@@ -53,7 +76,33 @@ class BylawDocumentController extends Controller
public function update(Request $request, BylawDocument $bylawDocument)
{
$data = $request->validate(['title' => 'required|string|max:1000', 'category_id' => 'nullable|exists:bylaw_subject_categories,id', 'approval_authority_id' => 'nullable|exists:bylaw_legal_authorities,id', 'approval_date' => 'nullable|date', 'promulgation_authority_id' => 'nullable|exists:bylaw_legal_authorities,id', 'promulgation_date' => 'nullable|date', 'promulgation_number' => 'nullable|string|max:100', 'official_gazette_number' => 'nullable|string|max:100', 'official_gazette_date' => 'nullable|date', 'execution_date' => 'nullable|date', 'bylaw_type' => 'required|in:executive,delegated,independent', 'global_status' => 'required|in:valid,explicitly_repealed,implicitly_repealed,annulled,expired,draft', 'pdf_file_path' => 'nullable|string|max:500', 'is_published' => 'nullable|boolean', 'description' => 'nullable|string']);
$data = $request->validate([
'title' => 'required|string|max:1000',
'category_id' => 'nullable|exists:bylaw_subject_categories,id',
'approval_authority_id' => 'nullable|exists:bylaw_legal_authorities,id',
'approval_date' => 'nullable|date',
'promulgation_authority_id' => 'nullable|exists:bylaw_legal_authorities,id',
'promulgation_date' => 'nullable|date',
'promulgation_number' => 'nullable|string|max:100',
'official_gazette_number' => 'nullable|string|max:100',
'official_gazette_date' => 'nullable|date',
'execution_date' => 'nullable|date',
'bylaw_type' => 'required|in:executive,delegated,independent',
'global_status' => 'required|in:valid,explicitly_repealed,implicitly_repealed,annulled,expired,draft',
'pdf_file' => 'nullable|file|mimes:pdf|max:20480',
'pdf_file_path' => 'nullable|string|max:500',
'is_published' => 'nullable|boolean',
'description' => 'nullable|string',
]);
if ($request->hasFile('pdf_file')) {
if ($bylawDocument->pdf_file_path && Storage::disk('public')->exists($bylawDocument->pdf_file_path)) {
Storage::disk('public')->delete($bylawDocument->pdf_file_path);
}
$data['pdf_file_path'] = $request->file('pdf_file')->store('pdfs', 'public');
}
$data['is_published'] = $request->boolean('is_published');
$bylawDocument->update($data);