diff --git a/app/Http/Controllers/PemilikJaminanController.php b/app/Http/Controllers/PemilikJaminanController.php index 7c38601..b8e0ecd 100644 --- a/app/Http/Controllers/PemilikJaminanController.php +++ b/app/Http/Controllers/PemilikJaminanController.php @@ -63,6 +63,7 @@ public function update(PemilikJaminanRequest $request, $id, $pemilik) { $validate = $request->validated(); + if ($validate) { try { $pemilik = PemilikJaminan::find($pemilik); @@ -88,6 +89,7 @@ $districts = District::where('city_code', $pemilik->city_code)->get(); $villages = Village::where('district_code', $pemilik->district_code)->get(); $hubunganPemilik = HubunganPemilikJaminan::all(); + $detailSertifikat = $pemilik->detail_sertifikat; return view( 'lpj::pemilik_jaminan.form', @@ -99,6 +101,7 @@ 'villages', 'hubunganPemilik', 'pemilik', + 'detailSertifikat' ), ); } diff --git a/app/Http/Requests/DebitureRequest.php b/app/Http/Requests/DebitureRequest.php index 7f83fbb..40b608e 100644 --- a/app/Http/Requests/DebitureRequest.php +++ b/app/Http/Requests/DebitureRequest.php @@ -4,6 +4,7 @@ use Illuminate\Foundation\Http\FormRequest; use Modules\Lpj\Rules\UniqueCifExceptZero; + use Modules\Lpj\Rules\UniqueExcept; class DebitureRequest extends FormRequest { diff --git a/app/Http/Requests/PemilikJaminanRequest.php b/app/Http/Requests/PemilikJaminanRequest.php index b6e267d..ca76c83 100644 --- a/app/Http/Requests/PemilikJaminanRequest.php +++ b/app/Http/Requests/PemilikJaminanRequest.php @@ -26,6 +26,7 @@ 'address' => 'nullable|string', 'postal_code' => 'nullable|string|max:10', 'status' => 'nullable|boolean', + 'detail_sertifikat' => 'nullable|string|max:255', ]; //$rules['nomor_id'] = 'nullable|max:16|unique:pemilik_jaminan,nomor_id,debiture_id,' . $this->debiture_id; @@ -41,4 +42,26 @@ { return true; } + + public function prepareForValidation() { + + $detailSertifikat = []; + $names = $this->input('detail_sertifikat.name', []); + $nomorIds = $this->input('detail_sertifikat.nomor_id', []); + + foreach ($names as $index => $name) { + if (isset($nomorIds[$index])) { + $detailSertifikat[] = [ + 'name' => $name, + 'nomor_id' => $nomorIds[$index] + ]; + } + } + + $this->merge([ + 'detail_sertifikat' => json_encode($detailSertifikat), + ]); + + + } } diff --git a/app/Models/PemilikJaminan.php b/app/Models/PemilikJaminan.php index d92dc0c..6f0addc 100644 --- a/app/Models/PemilikJaminan.php +++ b/app/Models/PemilikJaminan.php @@ -30,7 +30,8 @@ class PemilikJaminan extends Base 'status', 'authorized_at', 'authorized_status', - 'authorized_by' + 'authorized_by', + 'detail_sertifikat', ]; public function province() diff --git a/app/Rules/UniqueCifExceptZero.php b/app/Rules/UniqueCifExceptZero.php index c8173d1..03accd3 100644 --- a/app/Rules/UniqueCifExceptZero.php +++ b/app/Rules/UniqueCifExceptZero.php @@ -1,25 +1,32 @@ id = $id; - } + protected $id; - public function validate($attribute, $value, $fail): void - { - if (Debiture::where($attribute, $value) - ->where('id', '!=', $this->id) - ->where($attribute, '!=', '0000000000') - ->exists()) { - $fail('The :attribute field must be uniquse.'.$this->id); + public function __construct($id = null) + { + $this->id = $id; + } + + /** + * Run the validation rule. + */ + public function validate(string $attribute, mixed $value, Closure $fail) + : void { + if ($value !== '0000000000' && $value !== null && Debiture::query()->where($attribute, $value)->when( + $this->id, + function ($query) { + $query->where('id', '!=', $this->id); + }, + )->exists()) { + $fail('The :attribute field must be unique.'); + } } } -} diff --git a/database/migrations/2024_11_01_023117_update_debitures_table.php b/database/migrations/2024_11_01_023117_update_debitures_table.php new file mode 100644 index 0000000..cadf6b0 --- /dev/null +++ b/database/migrations/2024_11_01_023117_update_debitures_table.php @@ -0,0 +1,28 @@ +dropUnique(['cif']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('debitures', function (Blueprint $table) { + $table->string('cif')->unique()->change(); + }); + } +}; diff --git a/database/migrations/2024_11_01_083625_update_pemilik_jaminan_table.php b/database/migrations/2024_11_01_083625_update_pemilik_jaminan_table.php new file mode 100644 index 0000000..ec38fd5 --- /dev/null +++ b/database/migrations/2024_11_01_083625_update_pemilik_jaminan_table.php @@ -0,0 +1,28 @@ +string('detail_sertifikat')->nullable()->after('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('pemilik_jaminan', function (Blueprint $table) { + $table->dropColumn('detail_sertifikat'); + }); + } +}; diff --git a/resources/views/pemilik_jaminan/form.blade.php b/resources/views/pemilik_jaminan/form.blade.php index 03c4a11..27af2b1 100644 --- a/resources/views/pemilik_jaminan/form.blade.php +++ b/resources/views/pemilik_jaminan/form.blade.php @@ -79,7 +79,7 @@ @enderror