Home > Blockchain >  vlaue of checkbox to database in vue laravel
vlaue of checkbox to database in vue laravel

Time:05-18

i have this input:

<div >
<label for="patymentTerms">Payment Terms</label>
<b-form-checkbox id="patymentTerms" :checked="true" switch v-model="rForm.payment_terms" />
</div>

and this is the data:

data() {
return {
  rForm: {
    payment_terms: "",
  },
};

},

i am able to store data and other inputs in database but i'm a bit confused of how can i return false or true to of this input

CodePudding user response:

You can do it like this:

data() {
   return {
     rForm: {
        payment_terms: 0,
      },
    };

on on your controller:

$payment_terms = $request->payment_terms == 1 ? 1 : 0;

CodePudding user response:

You can simply achieve this by using only v-model.

Demo :

new Vue({
  el: "#app",
  data() {
    return {
      rForm: {
        payment_terms: false,
      }
    }
  },
  methods: {
    getCheckboxValue() {
        console.log(this.rForm.payment_terms);
    }
  }
});
<link type="text/css" rel="stylesheet" href="https://unpkg.com/[email protected]/dist/css/bootstrap.min.css" />
<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-vue.min.js"></script>


<div id="app">
  <label for="patymentTerms">Payment Terms</label>
  <b-form-checkbox v-model="rForm.payment_terms" @change="getCheckboxValue" />
</div>

  • Related