0
votes

I wanna input data to database from Select Option Form. I used Laravel and Vue. This is my Form

<div class="form-group">
   <label for="exampleFormControlSelect1">Pemilihan*</label>
   <select class="form-control" id="electionId" name="electionId" v-model="electionIdSelected">
     <option v-for="option in electionIdOptions" v-bind:value="option.value">{{option.text}}</option>
   </select>
</div>

This is my Vue:

data() {
          return{
                 electionIdSelected:'Please choose one',
                 electionIdOptions:[
                   {text: 'Presiden', value: 'ppwp'},
                   {text: 'DPRD Provinsi', value: 'pdpr'}
                 ],
           methods: {
            onSubmit() {
                axios.post('/psu/list/store', {
                   electionIdSelected: this.electionIdSelected,
                }).then(response => {
                   this.electionIdSelected = ''
             });
            }

This is my Controller in Laravel:

public function store(){
      $psu = new Psu;

      $psu->jenis_pemilihan = request('electionId');

      $psu->save();
    }

Please help me to insert form Select option into database. I still got error. This is an Error Message:

null value in column "jenis_pemilihan" violates not-null constraint

Cant get value to Controller and Model.

2
what error are you facing. please mention also.H45H
Good question, would be perfect if you could share exactly what the error told you.vahdet
The js for your vue component seems to be missing some }Rwd
Like @vahdet said, you need to elaborate on the error, or there's not much to answer.MTran
Thank you for respond. I already update Error MessageDavid Winalda

2 Answers

0
votes
public function store(Request $request){
  $psu = new Psu;

  $psu->jenis_pemilihan = $request->input('electionIdSelected');

  $psu->save();
}

I think electionId is empty in your controller because you never set such a key in the axios post ?

0
votes

You can try to send electionIdSelected.text for that your selectbox model is electionIdSelected when u set your option.text to the model then your values look like electionIdSelected.text

Just replace this line : electionIdSelected: this.electionIdSelected to electionIdSelected: this.electionIdSelected.text