Files
lpj/app/Services/PermohonanHistoryService.php
Daeng Deni Mardaeni 9af9c343d1 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.
2024-11-18 14:18:34 +07:00

37 lines
1.3 KiB
PHP

<?php
namespace Modules\Lpj\Services;
use Modules\Lpj\Models\Permohonan;
use Modules\Lpj\Models\PermohonanHistory;
class PermohonanHistoryService
{
public function createHistory(Permohonan $permohonan, string $status, ?string $keterangan, array $beforeRequest, array $afterRequest, ?string $filePath = null)
{
try {
$history = PermohonanHistory::create([
'permohonan_id' => $permohonan->id,
'status' => $status,
'keterangan' => $keterangan,
'before_request' => json_encode($beforeRequest),
'after_request' => json_encode($afterRequest),
'file_path' => $filePath,
'user_id' => auth()->id(),
]);
} catch (\Exception $e) {
// Log the error
\Log::error('Error creating PermohonanHistory: ' . $e->getMessage());
// You might want to delete the uploaded file if the database operation fails
if ($filePath) {
\Storage::disk('public')->delete($filePath);
}
// Rethrow the exception or handle it as per your application's error handling policy
throw new \Exception('Failed to create PermohonanHistory: ' . $e->getMessage());
}
}
}