Membuat Fitur Menu KJPP part 2

This commit is contained in:
2024-09-24 17:41:24 +07:00
parent 8b4dd34b51
commit 33ba88a276
5 changed files with 24 additions and 27 deletions

View File

@@ -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');
}
}

View File

@@ -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!',
];