Laravel Eloquent insertOrIgnore() Query Example

10-Apr-2023

.

Admin

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...

#Laravel 7

#Laravel

#Laravel 6