fix(trash): preserve photos during soft delete and only erase physical files on force delete
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user