Insert with relationship N: N

0

Ihavethesetextinputs,inawaypeoplecanchoosetofillthemornot.Orjustfillinsomeofthem.Isendthedataofthisformviaaxiosinanarray(Idonotknowifitisthebestway,soI'mheredoingthispost).Explainingmore,thisformwouldbethetaxes(Taxes)thatispartofaproductform(Products).

AndforthisIcreate3tablesinlaravel.AtableforProducts,anotherfor%withapivottable,relatingtheidofbothbutwithonemorefield,whichinthiscaseistheTaxes_names,thatwouldstorethevalueplacedintheseinputtext.>

Inlaravel,Irequestthisarrayasfollows.

$taxes=$request->taxes;

Therelationshipissetupandcorrect.Icanenterthedataviaquietbankanddebug,etc.

pivottablevalue:id|product_id|taxes_id

Let'ssaythatintheproduct_taxestableyouhavethefollowingdata:

id|name|-----------------------1|cfop|2|cst/csosnicms|3|cstpis(danfe)|4|cstcofins(danfe)|

Myproblemis,asI'llpulltheidscorrectlyfromthattableandmoveontothepivottable,alongwiththosefilledforms.

Modelofclasstaxes_name:

publicfunctiontaxes(){return$this->belongsToMany('App\TaxesNames','product_taxes','product_id','taxes_id')->withPivot('value');}

Arrayreceivedinlaravel

array('cfop'=>'12','cst'=>'2','cstPis'=>'3','cstCofins'=>'4',)

Axios:

this.axios.post('http://chart.solutions/public/api/produto',{nome:this.nome,codigo:this.codigo,preco:this.preco,group:this.selectedgroup,subgroup:this.selectedsubgroup,taxes:this.taxes}).then((response)=>{if(response.data.success){this.clearForm()this.productSwal("success")
                    console.log(this.taxes)
                }
            })
            .catch((error) => {
                    this.productSwal("error") 
            });
    
asked by anonymous 16.11.2018 / 17:00

0 answers