PHPackages                             mpyw/laravel-retry-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. mpyw/laravel-retry-on-duplicate-key

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

mpyw/laravel-retry-on-duplicate-key
===================================

Automatically retry non-atomic upsert operation when unique constraints are violated.

v1.3.3(3y ago)1352.9k↓50%1MITPHPPHP ^8.0

Since Nov 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mpyw/laravel-retry-on-duplicate-key)[ Packagist](https://packagist.org/packages/mpyw/laravel-retry-on-duplicate-key)[ RSS](/packages/mpyw-laravel-retry-on-duplicate-key/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (10)Versions (16)Used By (0)

Laravel Retry on Duplicate Key [![Build Status](https://github.com/mpyw/laravel-retry-on-duplicate-key/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/laravel-retry-on-duplicate-key/actions) [![Coverage Status](https://camo.githubusercontent.com/4fb65b0861134539ce53c1f53c367740cfd2d78fc65f28205b3ec8da4a726854/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d7079772f6c61726176656c2d72657472792d6f6e2d6475706c69636174652d6b65792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mpyw/laravel-retry-on-duplicate-key?branch=master)
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-retry-on-duplicate-key--)

Caution

**ABANDONED: Due to changes in Laravel [v10.29.0](https://github.com/laravel/framework/releases/tag/v10.29.0), the functionalities of this library have been integrated into the Laravel core, making the library unnecessary in most cases. Therefore, maintenance will be discontinued. From now on, retry processing will be automatically performed in `Model::createOrFirst()`, `Model::firstOrCreate()`, and `Model::updateOrCreate()`. The only pattern that still has value is for `Model::firstOrNew() + save()`, but since equivalent processing can be written by yourself, please do not use this library anymore.**

Automatically retry **non-atomic** upsert operation when unique constraints are violated.

e.g. `firstOrCreate()` `updateOrCreate()` `firstOrNew() + save()`

Original Issue: [Duplicate entries on updateOrCreate · Issue #19372 · laravel/framework](https://github.com/laravel/framework/issues/19372#issuecomment-584676368)

Requirements
------------

[](#requirements)

PackageVersionMandatoryPHP`^8.0`✅Laravel`^9.0 || ^10.0`✅[mpyw/laravel-unique-violation-detector](https://github.com/mpyw/laravel-unique-violation-detector)`^1.0`✅PHPStan`>=1.1`Installing
----------

[](#installing)

```
composer require mpyw/laravel-retry-on-duplicate-key

```

Basic usage
-----------

[](#basic-usage)

Important

The default implementation is provided by `ConnectionServiceProvider`, however, **package discovery is not available**. Be careful that you MUST register it in **`config/app.php`** by yourself.

```
