【发布时间】:2021-01-29 22:33:59
【问题描述】:
我需要在数据库中插入多条记录。目前我正在插入循环,当记录很大时会导致超时。有什么不使用循环的方法吗?
$consignments = Consignment::select('id')->where('customer_id',$invoice->customer_id)->doesntHave('invoice_charges')->get();
foreach($consignments as $consignment){
InvoiceCharge::create(['invoice_id'=>$invoice->id,'object_id'=>$consignment->id,'model'=>'Consignment']);
}
寄售在模型中有hasOne 关系
public function invoice_charges()
{
return $this->hasOne('App\Models\Admin\InvoiceCharge', 'object_id')->where('model', 'Consignment');
}
【问题讨论】:
标签: laravel laravel-5 eloquent query-builder