How to inserting multiple records in database Laravel 6?

Today, We want to share with you How to inserting multiple records in database Laravel 6?.In this post we will show you Insert Multiple Records At Once With Laravel 6, hear for laravel insert multiple records eloquent we will give you demo and example for implement.In this post, we will learn about How to insert multiple rows from a single query using eloquent/fluent with an example.

How to inserting multiple records in database Laravel 6?

There are the Following The simple About How to insert multiple rows in database Laravel 6? Full Information With Example and source code.

Read Also:  Remove specific value from php array

As I will cover this Post with live Working example to develop laravel insert data into multiple tables, so the Laravel 6 Insert multiple records in one query is used for this example is following below.

Laravel inserting multiple records in table

Syntax: How to insert multiple rows in database Laravel 6?

DB::table('yourTableName')
    ->insert(array(
        array(...),
        array(...),
        array(...),
        .....
    ));

Way : 1 laravel 6 insert multiple rows of table
DB::table('products')->insert(array(
array("id"=>'11',"product_name"=>"Mobile","product_code"=>"Mobile_007"),
array("id"=>'12',"product_name"=>"LCD","product_code"=>"LCD_9898"),
array("id"=>'13',"product_name"=>"Virat_bat","product_code"=>"Virat_bat_4141"),
array("id"=>'14',"product_name"=>"Kwid","product_code"=>"Kwid_0692"),
array("id"=>'15',"product_name"=>"Laptop","product_code"=>"Laptop_z570"),
);

Way : 2 laravel 6 bulk insert

$product1 = array("id"=>'11',"product_name"=>"Mobile","product_code"=>"Mobile_007");
$product2 = array("id"=>'12',"product_name"=>"LCD","product_code"=>"LCD_9898");
$product3 = array("id"=>'13',"product_name"=>"Virat_bat","product_code"=>"Virat_bat_4141");
$product4 = array("id"=>'14',"product_name"=>"Kwid","product_code"=>"Kwid_0692");
$product5 = array("id"=>'15',"product_name"=>"Laptop","product_code"=>"Laptop_z570");
DB::table('products')->insert(array($product1,$product2,$product3,$product4,$product5,));

Web Programming Tutorials Example with Demo

Read :

Read Also:  how to disable previous date in html?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel multiple data insert into database.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.