solve view-controller dropzone
This commit is contained in:
@@ -302,6 +302,22 @@ class PetaniLahanController extends Controller
|
|||||||
$fotoLama = [];
|
$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')) {
|
if ($request->hasFile('foto')) {
|
||||||
foreach ($request->file('foto') as $file) {
|
foreach ($request->file('foto') as $file) {
|
||||||
$path = $file->store('lahan', 'public');
|
$path = $file->store('lahan', 'public');
|
||||||
@@ -315,7 +331,7 @@ class PetaniLahanController extends Controller
|
|||||||
unset($validated['foto']);
|
unset($validated['foto']);
|
||||||
|
|
||||||
$lahan->update([...$validated,
|
$lahan->update([...$validated,
|
||||||
'foto' => count($fotoLama) > 0 ? $fotoLama : null,
|
'foto' => count($fotoLama) > 0 ? json_encode($fotoLama) : null,
|
||||||
'updated_by' => auth()->id()]
|
'updated_by' => auth()->id()]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -763,7 +763,8 @@
|
|||||||
let mockFile = {
|
let mockFile = {
|
||||||
name: "Foto Lahan " + (index + 1),
|
name: "Foto Lahan " + (index + 1),
|
||||||
size: 1024,
|
size: 1024,
|
||||||
id: index,
|
id: index,
|
||||||
|
file_path: pathStr,
|
||||||
isServerFile: true,
|
isServerFile: true,
|
||||||
accepted: true
|
accepted: true
|
||||||
};
|
};
|
||||||
@@ -782,7 +783,7 @@
|
|||||||
let deleteInput = $('<input>').attr({
|
let deleteInput = $('<input>').attr({
|
||||||
type: 'hidden',
|
type: 'hidden',
|
||||||
name: 'deleted_photos[]',
|
name: 'deleted_photos[]',
|
||||||
value: file.id
|
value: file.file_path
|
||||||
});
|
});
|
||||||
$('#deleted-photos-container').append(deleteInput);
|
$('#deleted-photos-container').append(deleteInput);
|
||||||
}
|
}
|
||||||
@@ -811,7 +812,7 @@
|
|||||||
let deleteInput = $('<input>').attr({
|
let deleteInput = $('<input>').attr({
|
||||||
type: 'hidden',
|
type: 'hidden',
|
||||||
name: 'deleted_photos[]',
|
name: 'deleted_photos[]',
|
||||||
value: fileToReplace.id
|
value: fileToReplace.file_path
|
||||||
});
|
});
|
||||||
$('#deleted-photos-container').append(deleteInput);
|
$('#deleted-photos-container').append(deleteInput);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user