solve view-controller dropzone
This commit is contained in:
@@ -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()]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user