How to Insert Multiple Records in Laravel?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show you How to Insert Multiple Records in Laravel? When we are working with any big project . On that times we may be need to add the multiple rows on our database by using laravel eloquent. Here we know that laravel provide us insert method for the bulk records create on the db.

So now in the bellow example we can see that here i am using multidimensional array as name $myItems. On this array the variable and that will be insert with multiple records same time by using DB::insert().

So let’s start and try this.

Example:
$myItems = [
            ['title'=>'Html','description'=>'codings point html'],
            ['title'=>'CSS','description'=>'codings point CSS'],
            ['title'=>'php','description'=>'codings point php'],
            ['title'=>'Laravel','description'=>'codings point laravel']
        ];


DB::table("programmings")->insert($myItems);

Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →