Laravel Eloquent insertOrIgnore() Query Example

Laravel 6 , Laravel , Laravel 7

Nicesnippets

7008

18-07-2020


Laravel Eloquent insertOrIgnore() Query Example

Hi Guys,

In this blog, I would like to share with you how to use insertorignore query in laravel application.

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

The insertOrIgnore method will ignore duplicate record errors while inserting records into the database.

Here I will give two example for laravel insertOrIgnore query. So let's see the bellow example.

Example 1 : Query


/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

DB::table('users')->insertOrIgnore([

['name' => 'taylor', 'email' => 'taylor@example.com'],

['name' => 'dayle', 'email' => 'dayle@example.com'],

]);

}

Example 2 : Query

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

User::insertOrIgnore([

['name' => 'taylor', 'email' => 'taylor@example.com'],

['name' => 'dayle', 'email' => 'dayle@example.com'],

]);

}

It will help you...


Recommended Posts