How can the code be modified to ensure that the bootstrap 4-toggle correctly updates the database with a value of 0 when deactivated?

The issue can be solved by adding a hidden input field that will send a value of 0 to the database when the bootstrap 4-toggle is deactivated. This hidden input field will be updated dynamically based on the toggle's state using JavaScript. By doing this, the database will be correctly updated with a value of 0 when the toggle is deactivated.

<input type="hidden" name="toggle_value" id="toggle_value" value="1">

<script>
$('#toggle').change(function() {
    if($(this).prop('checked')) {
        $('#toggle_value').val('1');
    } else {
        $('#toggle_value').val('0');
    }
});
</script>