New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jangaraev/eloquent-model-advisory-lock

Handy approach to avoid race conditions when doing upserts in Laravel Eloquent models
1,006
Install
composer require jangaraev/eloquent-model-advisory-lock
Latest Version:1.0.0
PHP:>=7.4
Laravel:7 – 13
License:MIT
Last Updated:Oct 5, 2026
Links: GitHub  ·  Packagist
Maintainer: jangaraev

eloquent-model-advisory-lock

Often you face the race conditions error when working with DB-intensive operations.

This package contains a trait with the method which helps to avoid that.

Usage

First do reference the trait in your model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Jangaraev\EloquentModelAdvisoryLock\AppliesAdvisoryLock;

class Foo extends Model
{
    use AppliesAdvisoryLock;
    
    // ...
}

This trait introduces the advisoryLock() method which receives a callable to execute.

You then can use this method to wrap your DB intensive calls.

// wrap you DB-intensive operations as a callable to the advisoryLock call
static::advisoryLock(fn () => $this->coolRelationship()->firstOrCreate());

Related Packages

neuecommerce/model-casts

Some handy Laravel Eloquent model casts.

24,914 0
ed-fruty/laravel-custom-model-builder

Custom model query builder for Laravel Eloquent

72 1
laravel-clickhouse/laravel-clickhouse

A ClickHouse based Eloquent model and Query builder for Laravel

130,611 233
pharaonic/laravel-sluggable

Simple, multi-column slugs for Laravel Eloquent models, powered by Pharaonic PHP...

1,013 8

Version History

Version Released PHP Laravel License
1.0.0 >=7.4 ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0||^13.0 MIT
0.91 >=7.4 ^7.0|^8.0|^9.0|^10.0|^11.0 MIT
0.9 >=7.4 ^7.0|^8.0|^9.0 MIT