petani lahan hapus
This commit is contained in:
@@ -379,9 +379,23 @@ class PetaniLahanController extends Controller
|
|||||||
return redirect()->route('petani.lahan-tanaman.index', $petaniId)->with('success', 'Lahan berhasil diperbarui.');
|
return redirect()->route('petani.lahan-tanaman.index', $petaniId)->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)
|
public function summary(string $petaniId)
|
||||||
|
|||||||
@@ -403,6 +403,7 @@
|
|||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col-12 text-end">
|
<div class="col-12 text-end">
|
||||||
<a href="{{ route('petani.index') }}" class="btn btn-secondary me-2 wave-effect wave-light">Kembali</a>
|
<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>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
@@ -1017,7 +1018,7 @@
|
|||||||
showConfirmButton: false,
|
showConfirmButton: false,
|
||||||
timer: 1500
|
timer: 1500
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
window.location.href = "{{ route('petani.index') }}";
|
window.location.href = "{{ route('petani.lahan-tanaman.index', ['petani' => $petani->id]) }}";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function(xhr) {
|
error: function(xhr) {
|
||||||
@@ -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();
|
initWilayah();
|
||||||
initKomoditas();
|
initKomoditas();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user