From 33ba88a2762f8fb72e3e7d3c5651b6163b926858 Mon Sep 17 00:00:00 2001 From: rahmatrafli1 Date: Tue, 24 Sep 2024 17:41:24 +0700 Subject: [PATCH] Membuat Fitur Menu KJPP part 2 --- app/Http/Controllers/KJPPController.php | 29 +++++++++---------- app/Http/Requests/KJPPRequest.php | 7 ++--- .../2024_09_18_084905_create_kjpp_table.php | 2 +- resources/views/kjpp/create.blade.php | 9 +++--- resources/views/kjpp/index.blade.php | 4 +-- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/app/Http/Controllers/KJPPController.php b/app/Http/Controllers/KJPPController.php index b854533..8be9d4d 100644 --- a/app/Http/Controllers/KJPPController.php +++ b/app/Http/Controllers/KJPPController.php @@ -6,17 +6,14 @@ use Illuminate\Http\Request; use Modules\Lpj\Models\KJPP; use Illuminate\Http\Response; use Modules\Lpj\Models\Branch; -use Modules\Location\Models\City; use Modules\Lpj\Models\IjinUsaha; use Modules\Lpj\Exports\KJPPExport; use App\Http\Controllers\Controller; use Maatwebsite\Excel\Facades\Excel; -use Modules\Location\Models\District; use Modules\Lpj\Models\JenisJaminan; use Modules\Location\Models\Province; -use Modules\Location\Models\Village; +use Illuminate\Support\Facades\Storage; use Modules\Lpj\Http\Requests\KJPPRequest; -use Throwable; class KJPPController extends Controller { @@ -49,22 +46,22 @@ class KJPPController extends Controller { $validate = $request->validated(); + if ($validate) { - try { - $file = $request->file('attachment'); - $filename = time() . '.' . $file->getClientOriginalExtension(); + $file = $request->file('attachment'); + $filename = $file ? time() . '.' . $file->getClientOriginalExtension() : 'default.pdf'; + if ($file) { $file->storeAs('uploads_pdf', $filename, 'public'); - - KJPP::create($validate); - return redirect() - ->route('basicdata.kjpp.index') - ->with('success', 'Ijin Usaha created successfully'); - } catch (Throwable $e) { - return redirect() - ->route('basicdata.kjpp.create') - ->with('error', 'Failed to create ijin Usaha: ' . $e); + } else { + Storage::copy('/home/bagi/Downloads/default.pdf', 'public/uploads_pdf/' . $filename); } + + dd($validate); + KJPP::create($validate); + return redirect() + ->route('basicdata.kjpp.index') + ->with('success', 'Ijin Usaha created successfully'); } } diff --git a/app/Http/Requests/KJPPRequest.php b/app/Http/Requests/KJPPRequest.php index f8fd822..b5f4622 100644 --- a/app/Http/Requests/KJPPRequest.php +++ b/app/Http/Requests/KJPPRequest.php @@ -32,9 +32,9 @@ class KJPPRequest extends FormRequest 'nomor_hp_pic_admin' => 'required|numeric|digits_between:10,15', 'nama_pic_marketing' => 'required|string|not_regex:/^\d+$/|max:255', 'nomor_hp_pic_marketing' => 'required|numeric|digits_between:10,15', - 'ijin_usaha_id' => 'nullable|exists:ijin_usaha,id', - 'jenis_aset_id' => 'nullable|exists:jenis_jaminan,id', - 'attachment' => 'required|mimes:pdf|max:1024' + 'ijin_usaha.*' => 'nullable', + 'jenis_jaminan.*' => 'nullable', + 'attachment' => 'nullable|mimes:pdf|max:1024' ]; if ($this->method() == 'PUT') { @@ -115,7 +115,6 @@ class KJPPRequest extends FormRequest 'nomor_hp_pic_marketing.required' => 'Nomor HP PIC Marketing Wajib diisi!', 'nomor_hp_pic_marketing.numeric' => 'Nomor HP PIC Marketing harus berupa angka!', 'nomor_hp_pic_marketing.digits_between' => 'Nomor HP PIC Marketing minimum 10 digit dan maksimum 15 digit!', - 'attachment.required' => 'Attachment Wajib diisi!', 'attachment.mimes' => 'Attachment harus berformat pdf!', 'attachment.max' => 'Attachment berukuran maksimum 1 MB!', ]; diff --git a/database/migrations/2024_09_18_084905_create_kjpp_table.php b/database/migrations/2024_09_18_084905_create_kjpp_table.php index 8f8ae24..387af1f 100644 --- a/database/migrations/2024_09_18_084905_create_kjpp_table.php +++ b/database/migrations/2024_09_18_084905_create_kjpp_table.php @@ -35,7 +35,7 @@ return new class extends Migration $table->string('nomor_hp_pic_marketing'); $table->string('ijin_usaha_id')->nullable(); $table->string('jenis_aset_id')->nullable(); - $table->string('attachment'); + $table->string('attachment')->nullable(); $table->boolean('status')->default(true)->nullable(); $table->char('authorized_status', 1)->nullable(); $table->timestamp('authorized_at')->nullable(); diff --git a/resources/views/kjpp/create.blade.php b/resources/views/kjpp/create.blade.php index 927857f..78db2c2 100644 --- a/resources/views/kjpp/create.blade.php +++ b/resources/views/kjpp/create.blade.php @@ -13,6 +13,7 @@ @method('PUT') @endif @csrf +

@@ -350,11 +351,11 @@ @if (isset($kjpp->ijin_usaha_id)) code, old('ijin_usaha_id', json_decode($kjpp->ijin_usaha_id, true)))) {{ 'checked' }} @endif - value="{{ $row->code }}" name="ijin_usaha_id[]" /> + value="{{ $row->code }}" name="ijin_usaha[]" /> @else code, old('ijin_usaha_id', []))) {{ 'checked' }} @endif - value="{{ $row->code }}" name="ijin_usaha_id[]" /> + value="{{ $row->code }}" name="ijin_usaha[]" /> @endif {{ $row->name }} @@ -373,11 +374,11 @@ @if (isset($kjpp->jenis_aset_id)) code, old('jenis_aset_id', json_decode($kjpp->jenis_aset_id, true)))) {{ 'checked' }} @endif - value="{{ $row->code }}" name="jenis_aset_id[]" /> + value="{{ $row->code }}" name="jenis_jaminan[]" /> @else code, old('jenis_aset_id', []))) {{ 'checked' }} @endif - value="{{ $row->code }}" name="jenis_aset_id[]" /> + value="{{ $row->code }}" name="jenis_jaminan[]" /> @endif {{ $row->name }} diff --git a/resources/views/kjpp/index.blade.php b/resources/views/kjpp/index.blade.php index cd131b7..40cf230 100644 --- a/resources/views/kjpp/index.blade.php +++ b/resources/views/kjpp/index.blade.php @@ -123,10 +123,10 @@ return checkbox.outerHTML.trim(); }, }, - nomor: { + code: { title: 'Nomor KJPP', }, - nama_kjpp: { + name: { title: 'Nama KJPP', }, jenis_kantor: {