diff --git a/app/Http/Controllers/Admin/BylawDocumentController.php b/app/Http/Controllers/Admin/BylawDocumentController.php index 080adf8..7eb11fc 100644 --- a/app/Http/Controllers/Admin/BylawDocumentController.php +++ b/app/Http/Controllers/Admin/BylawDocumentController.php @@ -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); diff --git a/resources/views/admin/bylaw-document/create.blade.php b/resources/views/admin/bylaw-document/create.blade.php index 760c4fe..a57b109 100644 --- a/resources/views/admin/bylaw-document/create.blade.php +++ b/resources/views/admin/bylaw-document/create.blade.php @@ -1,15 +1,171 @@ @extends('admin.layouts.app') @section('content') -
@endsection +اطلاعات سند را وارد کنید و در صورت نیاز فایل PDF را آپلود کنید.
+اطلاعات شناسنامهای، مرجع تصویب و وضعیت انتشار را در این بخش ویرایش کنید.
+