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,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
@include('lpj::component.detail-jaminan',['backLink' => 'authorization.index'])
|
||||
|
||||
<div class="card">
|
||||
<form action="{{ route('authorization.update', $permohonan->id) }}" method="POST" id="authorizationForm">
|
||||
<form action="{{ route('authorization.update', $permohonan->id) }}" method="POST" id="authorizationForm" enctype="multipart/form-data">
|
||||
<input type="hidden" name="_method" value="PUT">
|
||||
@csrf
|
||||
<div class="card-body lg:py-7.5">
|
||||
@@ -27,7 +27,7 @@
|
||||
Upload File Revisi
|
||||
</label>
|
||||
<div class="flex flex-wrap items-baseline w-full">
|
||||
<input type="file" class="file-input" id="revisionFile" name="revisionFile">
|
||||
<input type="file" class="file-input" id="revisionFile" name="attachment">
|
||||
<em class="alert text-danger text-sm hidden" id="file-message"></em>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user