Laravel

Laravel Eloquent: upsert for Bulk Operations

January 16, 2026 1 min read 17 views

Efficient bulk operations:

Basic Upsert

User::upsert([
    ['email' => 'john@example.com', 'name' => 'John'],
    ['email' => 'jane@example.com', 'name' => 'Jane'],
], ['email'], ['name']);

UpdateOrCreate

$user = User::updateOrCreate(
    ['email' => 'john@example.com'],
    ['name' => 'John Doe']
);

FirstOrCreate

$user = User::firstOrCreate(
    ['email' => 'john@example.com'],
    ['name' => 'John']
);

Insert Ignore

User::insertOrIgnore([
    ['email' => 'john@example.com'],
]);
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!