diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php
index f597537..47f08ee 100644
--- a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php
+++ b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php
@@ -302,6 +302,22 @@ class PetaniLahanController extends Controller
$fotoLama = [];
}
+ if ($request->has('deleted_photos') && is_array($request->deleted_photos)) {
+ foreach ($request->deleted_photos as $deletedPath) {
+
+ if (Storage::disk('public')->exists($deletedPath)) {
+ Storage::disk('public')->delete($deletedPath);
+ }
+
+ $fotoLama = array_filter($fotoLama, function($item) use ($deletedPath) {
+ $currentPath = is_array($item) ? ($item['path'] ?? '') : $item;
+ return $currentPath !== $deletedPath;
+ });
+ }
+ }
+
+ $fotoLama = array_values($fotoLama);
+
if ($request->hasFile('foto')) {
foreach ($request->file('foto') as $file) {
$path = $file->store('lahan', 'public');
@@ -315,7 +331,7 @@ class PetaniLahanController extends Controller
unset($validated['foto']);
$lahan->update([...$validated,
- 'foto' => count($fotoLama) > 0 ? $fotoLama : null,
+ 'foto' => count($fotoLama) > 0 ? json_encode($fotoLama) : null,
'updated_by' => auth()->id()]
);
diff --git a/resources/views/produktivitas/petani/lahan/edit.blade.php b/resources/views/produktivitas/petani/lahan/edit.blade.php
index 4e1d1e5..391dd8e 100644
--- a/resources/views/produktivitas/petani/lahan/edit.blade.php
+++ b/resources/views/produktivitas/petani/lahan/edit.blade.php
@@ -763,7 +763,8 @@
let mockFile = {
name: "Foto Lahan " + (index + 1),
size: 1024,
- id: index,
+ id: index,
+ file_path: pathStr,
isServerFile: true,
accepted: true
};
@@ -782,7 +783,7 @@
let deleteInput = $('').attr({
type: 'hidden',
name: 'deleted_photos[]',
- value: file.id
+ value: file.file_path
});
$('#deleted-photos-container').append(deleteInput);
}
@@ -811,7 +812,7 @@
let deleteInput = $('').attr({
type: 'hidden',
name: 'deleted_photos[]',
- value: fileToReplace.id
+ value: fileToReplace.file_path
});
$('#deleted-photos-container').append(deleteInput);
}