Site Admin
Site Admin Founder of MeaningArticles
998 Views

Laravel Insert Multiple Records In Database

Hello Dev.

If we work on huge project and then we maybe require to add a couple of rows on database the use of laravel eloquent. Laravel provide insert method for bulk records create on db.

In bellow instance you could see i take advantage of multidimensional $myItems array variable and that insert a couple of records same time the use of DB::insert(). So let's examine and do this.


Example:

$myItems = [
            ['title'=>'Iphone','description'=>'My Iphone 13'],
            ['title'=>'Nokia','description'=>'My Nokia 730'],
            ['title'=>'Samsung','description'=>'My Samsung Fold 3']
        ];

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

i'm hoping it assist you to, thanks for visit my article if you like my article then proportion together with your friend and social platform.