In this tutorial, we will see how to use insertorignore query in laravel application.
Given below are two examples for laravel insertOrIgnore query.
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'],
]);
}
I hope this example helps you.