Bulk Insertion in Laravel using eloquent ORM

phoenixwizard picture phoenixwizard · Oct 3, 2012 · Viewed 227.8k times · Source

How can we perform bulk database insertions in Laravel using Eloquent ORM?

I want to accomplish this in Laravel: https://stackoverflow.com/a/10615821/600516 but I am getting the following error.

SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters.

Answer

GTF picture GTF · Nov 28, 2012

You can just use Eloquent::insert().

For example:

$data = array(
    array('name'=>'Coder 1', 'rep'=>'4096'),
    array('name'=>'Coder 2', 'rep'=>'2048'),
    //...
);

Coder::insert($data);