fix(trash): preserve photos during soft delete and only erase physical files on force delete

This commit is contained in:
Ray1111-aa
2026-10-28 13:47:44 +07:00
parent af61766546
commit 852404be32
4 changed files with 57 additions and 11 deletions
+19
View File
@@ -17,6 +17,7 @@ use App\Models\UnitTransfer;
use App\Models\User;
use App\Models\Vehicle;
use App\Models\VehicleActivity;
use App\Services\ImageCompressionService;
use Carbon\Carbon;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@@ -432,6 +433,24 @@ class TrashService
->forceDelete();
}
// Hapus berkas fisik saat benar-benar dihapus permanen dari tong sampah
if ($item instanceof Vehicle) {
ImageCompressionService::deleteIfExists($item->photo_path);
if (method_exists($item, 'isSupportCategory') && $item->isSupportCategory()) {
foreach ($item->units as $u) {
ImageCompressionService::deleteIfExists($u->photo_path);
}
}
}
if ($item instanceof Employee) {
ImageCompressionService::deleteIfExists($item->photo_path);
}
if ($item instanceof User) {
ImageCompressionService::deleteIfExists($item->photo_path ?? null);
}
$item->forceDelete();
});