shuvobhai
4 months ago
690
8
Laravel

pivot table extra column

Posted 4 months ago by shuvobhai

how to add extra colmun in pivot table and those extra table will be an array -- laravel

Model ---------

public function purchases(){ return $this->belongsToMany('App\Purchase')->withPivot("cartoon","qty","rate","total"); }

Model ----

public function SupplierProducts(){ return $this->belongsToMany('App\SupplierProduct')->withPivot("cartoon","qty","rate","total"); }

Controller-------

$purchase = new Purchase; $purchase->supplier_id = $request->supplier; $purchase->purchase_date = $request->purchase_date; $purchase->purchase_no = $request->purchase_no; $purchase->purchase_details = $request->details; $purchase->payment_type = $request->payment_type; $purchase->grand_total = $request->grand_total; $purchase->save();

    $purchase->SupplierProducts()->sync($request->product_id,['cartoon'=> $request->cartoon,
                                                                'qty'=> $request->qty,
                                                                'rate'=> $request->rate,
                                                                'total'=> $request->total]);

Please sign in or create an account to participate in this conversation.