PHPackages                             rits-tecnologia/eloquent-insert-on-conflict - 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. rits-tecnologia/eloquent-insert-on-conflict

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

rits-tecnologia/eloquent-insert-on-conflict
===========================================

Macros for INSERT ON CONFLICT with Eloquent

v1.0.1(6y ago)14.2k1MITPHPPHP ^7.2

Since Jan 22Pushed 6y ago2 watchersCompare

[ Source](https://github.com/rits-tecnologia/eloquent-insert-on-conflict)[ Packagist](https://packagist.org/packages/rits-tecnologia/eloquent-insert-on-conflict)[ RSS](/packages/rits-tecnologia-eloquent-insert-on-conflict/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Laravel Insert On Conflict
==========================

[](#laravel-insert-on-conflict)

This package provides macros to run INSERT ... ON CONFLICT DO NOTHING or DO UPDATE SET queries on models with Laravel's ORM Eloquent using PostgreSQL.

Installation
------------

[](#installation)

Install this package with composer.

```
composer require rits-tecnologia/eloquent-insert-on-conflict
```

If you don't use Package Auto-Discovery yet add the service provider to your Package Service Providers in `config/app.php`.

```
InsertOnConflict\InsertOnConflictServiceProvider::class,
```

Usage
-----

[](#usage)

### Models

[](#models)

Call `insertOnConflict` from a model with the array of data to insert in its table.

```
$data = [
    ['id' => 1, 'name' => 'name1', 'email' => 'user1@email.com'],
    ['id' => 2, 'name' => 'name2', 'email' => 'user2@email.com'],
];

User::insertOnConflict($data);
```

#### Customizing the ON CONFLICT DO UPDATE clause

[](#customizing-the-on-conflict-do-update-clause)

##### Update only certain columns

[](#update-only-certain-columns)

If you want to update only certain columns, pass them as the 2nd argument.

```
User::insertOnConflict([
    'id'    => 1,
    'name'  => 'new name',
    'email' => 'foo@gmail.com',
], ['name'], 'do update set', 'id');
// The name will be updated but not the email.
```

##### Update with custom values

[](#update-with-custom-values)

You can customize the value with which the columns will be updated when a row already exists by passing an associative array.

In the following example, if a user with id = 1 doesn't exist, it will be created with name = 'created user'. If it already exists, it will be updated with name = 'updated user'.

```
User::insertOnConflict([
    'id'    => 1,
    'name'  => 'created user',
], ['name' => 'updated user'], 'do update set', 'id');
```

The generated SQL is:

```
INSERT INTO `users` (`id`, `name`) VALUES (1, "created user") ON CONFLICT (id) DO UPDATE SET `name` = "updated user"
```

You may combine key/value pairs and column names in the 2nd argument to specify the columns to update with a custom literal or expression or with the default `VALUES(column)`. For example:

```
User::insertOnConflict([
    'id'       => 1,
    'name'     => 'created user',
    'email'    => 'new@gmail.com',
    'password' => 'secret',
], ['name' => 'updated user', 'email'], 'do update set', 'id');
```

will generate

```
INSERT INTO `users` (`id`, `name`, `email`, `password`)
VALUES (1, "created user", "new@gmail.com", "secret")
ON CONFLICT (id) DO UPDATE SET `name` = "updated user", `email` = EXCLUDED.`email`
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Every ~78 days

Total

2

Last Release

2276d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f4c583e43b4a9522b43b49d73767f19af398ff1ede4d77846f4d4cc2803a52a?d=identicon)[jucianoaraujo](/maintainers/jucianoaraujo)

---

Tags

eloquentlaravelmacropostgresqllaraveldatabasepostgresqleloquent

### Embed Badge

![Health badge](/badges/rits-tecnologia-eloquent-insert-on-conflict/health.svg)

```
[![Health](https://phpackages.com/badges/rits-tecnologia-eloquent-insert-on-conflict/health.svg)](https://phpackages.com/packages/rits-tecnologia-eloquent-insert-on-conflict)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

592456.3k1](/packages/spiritix-lada-cache)[bosnadev/database

Eloquent Extended, added some PostgreSQL features

782.0M4](/packages/bosnadev-database)[guidocella/eloquent-populator

Guess attributes for Eloquent model factories

7762.7k2](/packages/guidocella-eloquent-populator)[mvanduijker/laravel-model-exists-rule

Validation rule to check if a model exists

22215.3k2](/packages/mvanduijker-laravel-model-exists-rule)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3262.5k4](/packages/toponepercent-baum)

PHPackages © 2026

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