Compare commits

2 Commits
2 changed files with 40 additions and 2 deletions
@@ -379,9 +379,23 @@ class PetaniLahanController extends Controller
return redirect()->route('petani.lahan-tanaman.edit', [$petaniId, $lahan->id])->with('success', 'Lahan berhasil diperbarui.');
}
public function destroy(string $id)
public function destroy(string $petaniId, string $id)
{
//
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
abort(403);
}
$lahan = Lahan::findOrFail($id);
$lahan->tanaman()->update([
'deleted_by' => auth()->id()
]);
$lahan->tanaman()->delete();
$lahan->update([
'deleted_by' => auth()->id()
]);
$lahan->delete();
return redirect()->route('petani.lahan-tanaman.index', $petaniId)->with('success', 'Lahan berhasil dihapus.');
}
public function summary(string $petaniId)
@@ -403,6 +403,7 @@
<div class="row mt-3">
<div class="col-12 text-end">
<a href="{{ route('petani.index') }}" class="btn btn-secondary me-2 wave-effect wave-light">Kembali</a>
<button id="delete-lahan"type="button" class="btn btn-danger data-submit wave-effect wave-light"><i class="ti tabler-trash me-2"></i> Hapus Lahan</button>
<button type="submit" class="btn btn-success data-submit wave-effect wave-light"><i class="ti tabler-device-floppy me-2"></i> Simpan Lahan</button>
</div>
</div>
@@ -1054,6 +1055,29 @@
}
});
$('#delete-lahan').click(function(e) {
e.preventDefault();
$.ajax({
url: "{{ route('petani.lahan-tanaman.destroy', ['petani' => $petani->id, 'lahan_tanaman' => $lahanSelected->id]) }}",
type: "POST",
data: {
_method: 'DELETE',
_token: $('input[name="_token"]').val()
},
success: function(res) {
Swal.fire({
icon: 'success',
title: 'Berhasil!',
text: 'Data lahan berhasil dihapus.',
showConfirmButton: false,
timer: 1500
}).then(() => {
window.location.href = "{{ route('petani.lahan-tanaman.index', ['petani' => $petani->id]) }}";
});
}
});
});
initWilayah();
initKomoditas();
});