请考虑我在Laravel 4中的数据库结构...
$table->increments('id');
$table->integer('user_id');
$table->integer('campaign_id');
$table->string('location');
$table->string('color');
$table->string('contacts');
$table->string('pickups');
$table->string('interviews');
$table->string('guest_posts');
$table->string('book_review_opp');
我有一个Campaign
表/模型,然后上面是一个Campaign Status's
表/模型,它属于Campaign
。
创建新的广告系列时,我必须插入上表中的50多个记录,每个美国州都应插入1条。我还必须添加所有加拿大领土。
因此,当我创建记录时以及编辑广告系列时,都会使用保存按钮显示每种状态的这些设置。
保存记录后,必须保存50个州以及加拿大地区。
我问是否有一种更有效的方式一次保存所有大量记录?
IMO,插入记录的最有效方法是:
DB::table('name')->insert(<array of 50 arrays>);
要么
CampaignStatus::query()->insert(<array of 50 arrays>);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句