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:
@@ -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,
|
||||
|
||||
@@ -7,15 +7,8 @@ use Modules\Lpj\Models\PermohonanHistory;
|
||||
|
||||
class PermohonanHistoryService
|
||||
{
|
||||
public function createHistory(Permohonan $permohonan, string $status, ?string $keterangan, array $beforeRequest, array $afterRequest, ?string $file = null)
|
||||
public function createHistory(Permohonan $permohonan, string $status, ?string $keterangan, array $beforeRequest, array $afterRequest, ?string $filePath = null)
|
||||
{
|
||||
|
||||
$filePath = null;
|
||||
if ($file) {
|
||||
$filePath = $file->store('permohonan_history_files', 'public');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$history = PermohonanHistory::create([
|
||||
'permohonan_id' => $permohonan->id,
|
||||
|
||||
Reference in New Issue
Block a user