Mass save records in Laravel 4?

JasonDavis

Please consider my Database structure in 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');

I have a Campaign table/model and then the above is a Campaign Status's table/model that belongs to a Campaign.

When I create a new campaign, I have to insert 50+ records from the above table, 1 for each US state. I also have to add all the Canadian Territories.

So when I create a record, also when I edit a campaign, I show these setting for each state with a save button.

Once a record is saved, it has to save the 50 states plus the Canada regions.

I am asking if there is a more efficient way of saving all the massive number of records at once?

Antonio Carlos Ribeiro

IMO, the most efficient way to insert records is:

DB::table('name')->insert(<array of 50 arrays>);

or

CampaignStatus::query()->insert(<array of 50 arrays>);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related