Recently in the use of laravel.
Want to BULK insert nearly thousands of data, know that direct write SQL can be bulk inserted.
In addition the framework ORM eloquent provides a create method:
/** * Save a new model and return the instance. * * @param array $attributes * @return \Illuminate\Database\Eloquent\Model|static */ public static function create(array $attributes) { $model = new static($attributes); $model->save(); return $model; }
This method can easily insert data, but cannot be inserted in bulk.
Based on performance considerations, do not want to write SQL, do eloquent have a method for this situation?
Reply content:
Recently in the use of laravel.
Want to BULK insert nearly thousands of data, know that direct write SQL can be bulk inserted.
In addition the framework ORM eloquent provides a create method:
/** * Save a new model and return the instance. * * @param array $attributes * @return \Illuminate\Database\Eloquent\Model|static */ public static function create(array $attributes) { $model = new static($attributes); $model->save(); return $model; }
This method can easily insert data, but cannot be inserted in bulk.
Based on performance considerations, do not want to write SQL, do eloquent have a method for this situation?
DB::table('users')->insert(array( array('email' => 'taylor@example.com', 'votes' => 0), array('email' => 'dayle@example.com', 'votes' => 0),));
Details