Update LetterController to handle nullable fields and set boolean flags for acceptance and completion letters
This commit is contained in:
@@ -103,18 +103,22 @@ class LetterController extends Controller
|
|||||||
'program_studi_mahasiswa' => 'required|string',
|
'program_studi_mahasiswa' => 'required|string',
|
||||||
'tahun_ajaran' => 'required|string',
|
'tahun_ajaran' => 'required|string',
|
||||||
'start_date' => 'required|date',
|
'start_date' => 'required|date',
|
||||||
'completion_date' => 'required|date',
|
'completion_date' => 'nullable|date',
|
||||||
|
'nomor_surat_acceptance' => 'nullable|string',
|
||||||
|
'nomor_surat_completion' => 'nullable|string',
|
||||||
'lampiran' => 'nullable|file|mimes:pdf,jpg,png|max:2048',
|
'lampiran' => 'nullable|file|mimes:pdf,jpg,png|max:2048',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Create letter with UUID and optional fields
|
// Automatically set boolean flags based on letter numbers
|
||||||
|
$is_acceptance = !empty($request->nomor_surat_acceptance);
|
||||||
|
$is_completion = !empty($request->nomor_surat_completion);
|
||||||
|
|
||||||
|
// Create letter with UUID and modified fields
|
||||||
$letter = Letter::create([
|
$letter = Letter::create([
|
||||||
'id' => Str::uuid()->toString(),
|
'id' => Str::uuid()->toString(),
|
||||||
...$validated,
|
...$validated,
|
||||||
'is_acceptance' => $request->is_acceptance ?? false,
|
'is_acceptance' => $is_acceptance,
|
||||||
'nomor_surat_acceptance' => $request->nomor_surat_acceptance,
|
'is_completion' => $is_completion,
|
||||||
'is_completion' => $request->is_completion ?? false,
|
|
||||||
'nomor_surat_completion' => $request->nomor_surat_completion,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Handle file upload if present
|
// Handle file upload if present
|
||||||
@@ -201,6 +205,15 @@ class LetterController extends Controller
|
|||||||
'lampiran' => 'nullable|file|mimes:pdf,jpg,png|max:2048',
|
'lampiran' => 'nullable|file|mimes:pdf,jpg,png|max:2048',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Update boolean flags if letter numbers are provided
|
||||||
|
if ($request->has('nomor_surat_acceptance')) {
|
||||||
|
$validated['is_acceptance'] = !empty($request->nomor_surat_acceptance);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('nomor_surat_completion')) {
|
||||||
|
$validated['is_completion'] = !empty($request->nomor_surat_completion);
|
||||||
|
}
|
||||||
|
|
||||||
$letter->update($validated);
|
$letter->update($validated);
|
||||||
|
|
||||||
if ($request->hasFile('lampiran')) {
|
if ($request->hasFile('lampiran')) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ return new class extends Migration
|
|||||||
$table->string('program_studi_mahasiswa');
|
$table->string('program_studi_mahasiswa');
|
||||||
$table->string('tahun_ajaran');
|
$table->string('tahun_ajaran');
|
||||||
$table->date('start_date');
|
$table->date('start_date');
|
||||||
$table->date('completion_date');
|
$table->date('completion_date')->nullable();
|
||||||
$table->string('lampiran')->nullable();
|
$table->string('lampiran')->nullable();
|
||||||
$table->boolean('is_acceptance')->default(false);
|
$table->boolean('is_acceptance')->default(false);
|
||||||
$table->string('nomor_surat_acceptance')->nullable();
|
$table->string('nomor_surat_acceptance')->nullable();
|
||||||
|
|||||||
Reference in New Issue
Block a user