PHPackages                             talentasia/eloquent-insert-on-duplicate-key - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. talentasia/eloquent-insert-on-duplicate-key

ActiveLibrary[Database &amp; ORM](/categories/database)

talentasia/eloquent-insert-on-duplicate-key
===========================================

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE with Eloquent.

0.1(8y ago)0315↓94.1%MITPHP

Since Aug 4Pushed 8y ago1 watchersCompare

[ Source](https://github.com/thosuperman/eloquent-insert-on-duplicate-key)[ Packagist](https://packagist.org/packages/talentasia/eloquent-insert-on-duplicate-key)[ Docs](https://github.com/thosuperman/eloquent-insert-on-duplicate-key)[ RSS](/packages/talentasia-eloquent-insert-on-duplicate-key/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

MySQL Insert On Duplicate Key Update Eloquent Trait
===================================================

[](#mysql-insert-on-duplicate-key-update-eloquent-trait)

[Insert Duplicate Key Update](http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html) is a quick way to do mass insert.

It's a trait meant to be used with Laravel's Eloquent ORM.

### Code Example

[](#code-example)

```
use Illuminate\Database\Eloquent\Model;
use TalentAsia\InsertOnDuplicateKey;

/**
 * Class User.
 */
class User extends Model
{
    // The function is implemented as a trait.
    use InsertOnDuplicateKey;
}
```

#### Multi values insert.

[](#multi-values-insert)

```
    $users = [
        ['id' => 1, 'email' => 'user1@email.com', 'name' => 'User 1'],
        ['id' => 2, 'email' => 'user2@email.com', 'name' => 'User 2'],
        ['id' => 3, 'email' => 'user3@email.com', 'name' => 'User 3'],
    ];
```

#### INSERT ON DUPLICATE KEY UPDATE

[](#insert-on-duplicate-key-update)

```
    User::insertOnDuplicateKey($users);
```

```
    -- produces this query
    INSERT INTO `users`(`id`,`email`,`name`) VALUES
    (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three')
    ON DUPLICATE KEY UPDATE `id` = VALUES(`id`), `email` = VALUES(`email`), `name` = VALUES(`name`)
```

```
    User::insertOnDuplicateKey($users, ['email']);
```

```
    -- produces this query
    INSERT INTO `users`(`id`,`email`,`name`) VALUES
    (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three')
    ON DUPLICATE KEY UPDATE `email` = VALUES(`email`)
```

#### INSERT IGNORE

[](#insert-ignore)

```
    User::insertIgnore($users);
```

```
    -- produces this query
    INSERT IGNORE INTO `users`(`id`,`email`,`name`) VALUES
    (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three');
```

#### REPLACE INTO

[](#replace-into)

```
    User::replace($users);
```

```
    -- produces this query
    REPLACE INTO `users`(`id`,`email`,`name`) VALUES
    (1,'user1@email.com','User One'), (2,'user3@email.com','User Two'), (3,'user3email.com','User Three');
```

### created\_at and updated\_at fields.

[](#created_at-and-updated_at-fields)

created\_at and updated\_at will *not* be updated automatically. To update you can pass the fields in the insert array.

```
['id' => 1, 'email' => 'user1@email.com', 'name' => 'User One', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]
```

### Run unit tests

[](#run-unit-tests)

```
./vendor/bin/phpunit

```

### Will this work on Postgresql?

[](#will-this-work-on-postgresql)

No. On Duplicate Key Update is only available on MySQL.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3256d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17564259?v=4)[Tho Nguyen](/maintainers/thosuperman)[@thosuperman](https://github.com/thosuperman)

---

Top Contributors

[![thosuperman](https://avatars.githubusercontent.com/u/17564259?v=4)](https://github.com/thosuperman "thosuperman (1 commits)")

---

Tags

databasemysqleloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/talentasia-eloquent-insert-on-duplicate-key/health.svg)

```
[![Health](https://phpackages.com/badges/talentasia-eloquent-insert-on-duplicate-key/health.svg)](https://phpackages.com/packages/talentasia-eloquent-insert-on-duplicate-key)
```

###  Alternatives

[yadakhov/insert-on-duplicate-key

A trait for MySQL INSERT ON DUPLICATE KEY UPDATE.

2753.0M8](/packages/yadakhov-insert-on-duplicate-key)[pecee/pixie

Lightweight, fast query-builder for PHP based on Laravel Eloquent but with less overhead.

4229.9k9](/packages/pecee-pixie)[moloquent/moloquent

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

120115.7k7](/packages/moloquent-moloquent)[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

62414.3k11](/packages/rah-danpu)[sarfraznawaz2005/indexer

Laravel package to monitor SELECT queries and offer best possible INDEX fields.

562.7k](/packages/sarfraznawaz2005-indexer)[zara-4/laravel-lazy-mysql

A lazy mysql based Eloquent model and Query builder for Laravel

127.9k](/packages/zara-4-laravel-lazy-mysql)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
