samedi 29 août 2020

Insert an Array of Checkbox Values with Laravel, Vue,js, and Axios

I am making a simple Workorder Form. I have two tables: workorders and units. Workorder model has many Unit and Unit model belongs to Workorder. I need to insert each array value (id only) into the units table. I will have multiple records to insert per query. What I have below is clearly not working.

The View

              <table>
                    <thead>
                    <tr>
                        <td>MFG</td>
                        <td>Build</td>
                        <td>SN</td>
                        <td>Type</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="hp in hps">
                        <td>
                            <input type="checkbox" :value="hp.id" v-model="checkedhps"><span class="checkbox-label"> </span>
                        </td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    </tbody>
                </table>

                <form @submit.prevent="onSubmit">
                   <div>
                     <input type="hidden" autocomplete='off'>
                   </div>
                   <div>
                     <button type="submit">Create</button>
                   </div>
                </form>

The Script

    export default {
    data: function() {
                return {
                    checkedhps:[],
                }
            },
            methods: {
                onSubmit(){
                    axios.post('/checkedHps', this.$data)
                    .then((response) => {
                        if(response.status===200) {
                           this.$router.push('/customer/'+this.customer.id)
                        }
                    })
                }
             }
         }

The Controller

public function store(Request $request){
    $hps = $request->input('checkedhps');
    foreach($hps as $hp){
        hp_wo::create($hp);
        }
    }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3b5wZx9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire