Laravel Eloquent insertOrIgnore() Query Example

Laravel eloquent insertOrIgnore query example; Through this tutorial, i am going to show you how to use insertOrIgnore() function with queries in laravel apps.

The use of insertOrIgnore query in laravel used to insert record but ignore duplicate record while inserting.

Example :- Laravel Eloquent insertOrIgnore() Query

Let’s see the first example of insertOrIgnore query in laravel; as follows:

DB::table('users')->insertOrIgnore([
    ['id' => 1, 'email' => '[email protected]'],
    ['id' => 2, 'email' => '[email protected]'],
]);

Note that:- The insertOrIgnore method will ignore errors while inserting records into the database.

Leave a Comment