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

Laravel batch insert data

angryTom
Release: 2023-04-07 17:16:01
forward
10102 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:
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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template