Home>Article>Backend Development> Laravel batch insert data
Implementation method
$data= [ ['name'=>'111'], ['name'=>'222'], ]; DB::table('xxx')->insert($data);
can also be added to the Model
class BaseModel extend Model { public function addAll(Array $data) { return DB::table($this->getTable())->insert($data); } } class User extend BaseModel{ }
//使用时$user = new User(); $data= [ ['name'=>'222'], ['name'=>'222'], ]; $user->addAll($data);
For more PHP related knowledge, please visitPHP Chinese website!
The above is the detailed content of Laravel batch insert data. For more information, please follow other related articles on the PHP Chinese website!