Home > Backend Development > PHP Tutorial > Laravel batch insert data

Laravel batch insert data

angryTom
Release: 2023-04-07 17:16:01
forward
10043 people have browsed it

Laravel batch insert data

Implementation method

$data= [
  ['name'=>'111'],
  ['name'=>'222'],
];
DB::table('xxx')->insert($data);
Copy after login

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{
 
}
Copy after login
//使用时$user = new User();
$data= [
  ['name'=>'222'],
  ['name'=>'222'],
];
 
$user->addAll($data);
Copy after login

For more PHP related knowledge, please visit PHP 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!

Related labels:
source:左鹏个人博客
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template