Laravel Eloquent insertOrIgnore() Query Example

Laravel insert or ignore query example; In this tutorial you will learn how to use insertOrIgnore eloquent query in laravel application. insertOrIgnore eloquent query will ignore duplicate records and also may ignore other types of errors depending on the database engine.

The insertOrIgnore method will ignore errors while inserting records into the database. Here I will give two example for laravel insertOrIgnore query. So let’s see the bellow example.

Laravel insertOrIgnore Example:

use App\Models\User;

class UserController extends Controller
{
    public function index()
    {
        User::insertOrIgnore([
            ['id' => 1, 'email' => 'sisko@example.com'],
            ['id' => 2, 'email' => 'archer@example.com'],
        ]);
    }
}

Please Note: 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.

Leave a Comment