Perbaiki pengelolaan dokumen pada History Permohonan

Mengganti field 'attachment' menjadi 'dokumen' pada model Permohonan dan mengupdate referensi terkait di view dan service. Juga menambahkan dukungan multipart/form-data pada form. Perubahan ini memperbaiki manajemen file yang diunggah dan memastikan integritas data terlindungi saat memperbarui permohonan.
This commit is contained in:
Daeng Deni Mardaeni
2024-11-18 14:17:19 +07:00
parent 77cc5a4b24
commit 9af9c343d1
3 changed files with 6 additions and 18 deletions

View File

@@ -2,6 +2,7 @@
namespace Modules\Lpj\Models;
use Illuminate\Support\Facades\Storage;
use Modules\Lpj\Database\Factories\PermohonanFactory;
use Modules\Lpj\Services\PermohonanHistoryService;
use Modules\Usermanagement\Models\User;
@@ -39,7 +40,6 @@ class Permohonan extends Base
'registrasi_at',
'jenis_penilaian_id',
'region_id',
'attachment'
];
protected static function boot()
@@ -70,12 +70,7 @@ class Permohonan extends Base
$fileName = time() . '_' . $file->getClientOriginalName();
$filePath = $file->storeAs('permohonan_attachments', $fileName, 'public');
// Delete old file if it exists
if ($permohonan->attachment) {
Storage::disk('public')->delete($permohonan->attachment);
}
$permohonan->attachment = $filePath;
$permohonan->dokumen = $filePath;
}
}
@@ -87,7 +82,7 @@ class Permohonan extends Base
$keterangan = request()->input('keterangan'); // Get keterangan from request
$beforeRequest = $action === 'updated' ? $permohonan->getOriginal() : [];
$afterRequest = $permohonan->toArray();
$file = $permohonan->attachment ? Storage::disk('public')->path($permohonan->attachment) : null;
$file = $permohonan->dokumen ? Storage::disk('public')->path($permohonan->dokumen) : null;
$historyService->createHistory(
$permohonan,