使用 eloquent ORM 在 Laravel 中批量插入 [英] Bulk Insertion in Laravel using eloquent ORM
本文介绍了使用 eloquent ORM 在 Laravel 中批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使用 Eloquent ORM 在 Laravel 中执行批量数据库插入?
How can we perform bulk database insertions in Laravel using Eloquent ORM?
我想在 Laravel 中完成此操作:https://stackoverflow.com/a/10615821/600516但我收到以下错误.
I want to accomplish this in Laravel: https://stackoverflow.com/a/10615821/600516 but I am getting the following error.
SQLSTATE[HY093]:无效的参数号:混合命名和位置参数.
SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters.
推荐答案
你可以直接使用 Eloquent::insert()
.
例如:
$data = array(
array('name'=>'Coder 1', 'rep'=>'4096'),
array('name'=>'Coder 2', 'rep'=>'2048'),
//...
);
Coder::insert($data);
这篇关于使用 eloquent ORM 在 Laravel 中批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文