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;
|
namespace Modules\Lpj\Models;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Modules\Lpj\Database\Factories\PermohonanFactory;
|
use Modules\Lpj\Database\Factories\PermohonanFactory;
|
||||||
use Modules\Lpj\Services\PermohonanHistoryService;
|
use Modules\Lpj\Services\PermohonanHistoryService;
|
||||||
use Modules\Usermanagement\Models\User;
|
use Modules\Usermanagement\Models\User;
|
||||||
@@ -39,7 +40,6 @@ class Permohonan extends Base
|
|||||||
'registrasi_at',
|
'registrasi_at',
|
||||||
'jenis_penilaian_id',
|
'jenis_penilaian_id',
|
||||||
'region_id',
|
'region_id',
|
||||||
'attachment'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static function boot()
|
protected static function boot()
|
||||||
@@ -70,12 +70,7 @@ class Permohonan extends Base
|
|||||||
$fileName = time() . '_' . $file->getClientOriginalName();
|
$fileName = time() . '_' . $file->getClientOriginalName();
|
||||||
$filePath = $file->storeAs('permohonan_attachments', $fileName, 'public');
|
$filePath = $file->storeAs('permohonan_attachments', $fileName, 'public');
|
||||||
|
|
||||||
// Delete old file if it exists
|
$permohonan->dokumen = $filePath;
|
||||||
if ($permohonan->attachment) {
|
|
||||||
Storage::disk('public')->delete($permohonan->attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
$permohonan->attachment = $filePath;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +82,7 @@ class Permohonan extends Base
|
|||||||
$keterangan = request()->input('keterangan'); // Get keterangan from request
|
$keterangan = request()->input('keterangan'); // Get keterangan from request
|
||||||
$beforeRequest = $action === 'updated' ? $permohonan->getOriginal() : [];
|
$beforeRequest = $action === 'updated' ? $permohonan->getOriginal() : [];
|
||||||
$afterRequest = $permohonan->toArray();
|
$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(
|
$historyService->createHistory(
|
||||||
$permohonan,
|
$permohonan,
|
||||||
|
|||||||
@@ -7,15 +7,8 @@ use Modules\Lpj\Models\PermohonanHistory;
|
|||||||
|
|
||||||
class PermohonanHistoryService
|
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 {
|
try {
|
||||||
$history = PermohonanHistory::create([
|
$history = PermohonanHistory::create([
|
||||||
'permohonan_id' => $permohonan->id,
|
'permohonan_id' => $permohonan->id,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
@include('lpj::component.detail-jaminan',['backLink' => 'authorization.index'])
|
@include('lpj::component.detail-jaminan',['backLink' => 'authorization.index'])
|
||||||
|
|
||||||
<div class="card">
|
<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">
|
<input type="hidden" name="_method" value="PUT">
|
||||||
@csrf
|
@csrf
|
||||||
<div class="card-body lg:py-7.5">
|
<div class="card-body lg:py-7.5">
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
Upload File Revisi
|
Upload File Revisi
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<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>
|
<em class="alert text-danger text-sm hidden" id="file-message"></em>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user