solve view-controller dropzone

This commit is contained in:
2026-07-21 11:49:32 +07:00
parent fbf84eb4cb
commit 8afe7f9b38
2 changed files with 21 additions and 4 deletions
@@ -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()]
);