feat(jenis-legalitas-jaminan): tambahkan dukungan untuk custom fields
- Menambahkan kolom 'custom_fields' pada tabel 'jenis_legalitas_jaminan'. - Memperbarui model untuk mengizinkan pengisian 'custom_fields' sebagai array. - Memperbarui request untuk validasi 'custom_fields' sebagai array. - Memperbarui controller untuk mengambil dan mengirimkan custom fields saat membuat dan mengedit jenis legalitas jaminan.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\JenisLegalitasJaminanExport;
|
||||
use Modules\Lpj\Http\Requests\JenisLegalitasJaminanRequest;
|
||||
use Modules\Lpj\Models\customField;
|
||||
use Modules\Lpj\Models\JenisLegalitasJaminan;
|
||||
|
||||
class JenisLegalitasJaminanController extends Controller
|
||||
@@ -40,13 +41,15 @@
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('lpj::jenis_legalitas_jaminan.create');
|
||||
$customFields = CustomField::orderBy('urutan_prioritas', 'asc')->get();
|
||||
return view('lpj::jenis_legalitas_jaminan.create',compact('customFields'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$jenisLegalitasJaminan = JenisLegalitasJaminan::find($id);
|
||||
return view('lpj::jenis_legalitas_jaminan.create', compact('jenisLegalitasJaminan'));
|
||||
$customFields = CustomField::orderBy('urutan_prioritas', 'asc')->get();
|
||||
return view('lpj::jenis_legalitas_jaminan.create', compact('jenisLegalitasJaminan', 'customFields'));
|
||||
}
|
||||
|
||||
public function update(JenisLegalitasJaminanRequest $request, $id)
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
'slug' => 'required|max:255',
|
||||
'custom_field' => 'nullable|max:255',
|
||||
'custom_field_type' => 'nullable|max:255',
|
||||
'custom_fields' => 'nullable|array',
|
||||
'custom_fields.*' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -46,5 +48,10 @@
|
||||
'slug' => Str::slug($this->name),
|
||||
]);
|
||||
}
|
||||
|
||||
// Ensure custom_fields is always an array
|
||||
if (!is_array($this->custom_fields)) {
|
||||
$this->merge(['custom_fields' => []]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,5 +7,14 @@
|
||||
class JenisLegalitasJaminan extends Base
|
||||
{
|
||||
protected $table = 'jenis_legalitas_jaminan';
|
||||
protected $fillable = ['code', 'name','slug','custom_field','custom_field_type'];
|
||||
protected $fillable = ['code', 'name','slug','custom_field','custom_field_type','custom_fields'];
|
||||
|
||||
protected $casts = [
|
||||
'custom_fields' => 'array',
|
||||
];
|
||||
|
||||
public function customFields()
|
||||
{
|
||||
return $this->hasMany(CustomField::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('jenis_legalitas_jaminan', function (Blueprint $table) {
|
||||
$table->string('custom_fields')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('jenis_legalitas_jaminan', function (Blueprint $table) {
|
||||
$table->dropColumn('custom_fields');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -79,6 +79,30 @@
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label class="form-label max-w-56">
|
||||
Custom Fields
|
||||
</label>
|
||||
<div class="grid grid-cols-3 lg:grid-cols-4 w-full gap-2.5">
|
||||
@foreach($customFields as $customField)
|
||||
<label class="switch">
|
||||
@if ( isset($jenisLegalitasJaminan) && !empty($jenisLegalitasJaminan->custom_fields))
|
||||
<input type="checkbox" @if (in_array($customField->id, $jenisLegalitasJaminan->custom_fields))
|
||||
{{ 'checked' }}
|
||||
@endif
|
||||
value="{{ $customField->id }}" name="custom_fields[]"/>
|
||||
@else
|
||||
<input type="checkbox" value="{{ $customField->id }}"
|
||||
name="custom_fields[]"/>
|
||||
@endif
|
||||
<span class="switch-label">
|
||||
{{ $customField->urutan_prioritas.'. '.$customField->label }}
|
||||
</span>
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="flex justify-end">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
|
||||
Reference in New Issue
Block a user