Laravel - Query Builder - Insert Statements

The query builder also provides an insert method that may be used to insert records into the database table. The insert method accepts an array of column names and values:

    
    DB::table('users')->insert([
        'email' => '[email protected]',
        'votes' => 0
    ]);
	

You may insert several records at once by passing an array of arrays. Each array represents a record that should be inserted into the table:

    
    DB::table('users')->insert([
        ['email' => '[email protected]', 'votes' => 0],
        ['email' => '[email protected]', 'votes' => 0],
    ]);
	

The insertOrIgnore method will ignore errors while inserting records into the database:

    
    DB::table('users')->insertOrIgnore([
        ['id' => 1, 'email' => '[email protected]'],
        ['id' => 2, 'email' => '[email protected]'],
    ]);
	
insertOrIgnore will ignore duplicate records and also may ignore other types of errors depending on the database engine. For example, insertOrIgnore will bypass MySQL's strict mode.