1 回答
TA贡献1873条经验 获得超9个赞
首先,您必须定义表之间的关系。
//QUOTATION Model
public function items()
{
return $this->hasMany('App\Item');
}
public function terms()
{
return $this->hasMany('App\TermCondition');
}
//ITEM Model
public function quotation()
{
return $this- belongsTo('App\Quotation','id_quotation');
}
//TermCondition Model
public function quotation()
{
return $this- belongsTo('App\Quotation','id_quotation');
}
现在在您的控制器中,当您成功更新报价时,然后更新其他表的其余部分。
public function update(Request $request) {
$quotation = Quotation::findOrFail($request->id);
$quotation->no_quotation = $request->no_quotation;
...
if($quotation->update()) {
$getQuotationID = $quotation->id;
for ($i = 1; $i <= count($request->items); $i++) {
$item = Item::where('id_quotation', $getQuotationID)->first();
$item->id_quotation = $getQuotationID;
...
$item->totalrate = $request->items[$i]['totalrate'];
$item->save();
};
for ($i = 1; $i <= count($request->terms); $i++) {
$term = TermCondition::where('id_quotation', $getQuotationID)->first();
$term->id_quotation = $getQuotationID;
$term->caption = $request->terms[$i]['caption'];
$term->save();
};
return redirect('quotation-show');
};
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报