phoenixwizard phoenixwizard - 3 months ago 14
PHP Question

Bulk Insertion in Laravel using eloquent ORM

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

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


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

GTF GTF
Answer

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);