PHPackages                             laravel-enso/lockable-models - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. laravel-enso/lockable-models

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laravel-enso/lockable-models
============================

Lockable models dependency for Laravel Enso

1.0.4(1mo ago)00MITPHPPHP ^8.3

Since Mar 3Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/laravel-enso/lockable-models)[ Packagist](https://packagist.org/packages/laravel-enso/lockable-models)[ Docs](https://github.com/laravel-enso/lockable-models)[ RSS](/packages/laravel-enso-lockable-models/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (6)Used By (0)

Lockable Models
===============

[](#lockable-models)

[![License](https://camo.githubusercontent.com/0e273da03dc26b4784be4a0f4a81e8cb016340afce3e2e48abf5383d1d009729/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f6c6f636b61626c652d6d6f64656c732f6c6963656e7365)](LICENSE)[![Stable](https://camo.githubusercontent.com/37042327eaa3d91b07a3e4beaa961380603500241d5fa29ea082d48e1a708dec/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f6c6f636b61626c652d6d6f64656c732f76657273696f6e)](https://packagist.org/packages/laravel-enso/lockable-models)[![Downloads](https://camo.githubusercontent.com/0216abd647a6b5deb6b75f9ea46718321850e262bee12ff18da24beb235ac459/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f6c6f636b61626c652d6d6f64656c732f646f776e6c6f616473)](https://packagist.org/packages/laravel-enso/lockable-models)[![PHP](https://camo.githubusercontent.com/76d2504e4f304c14866dd7295641dd6812652d93a1848a27fc8e2a08d6732731/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e332532422d3737376262342e737667)](composer.json)[![Issues](https://camo.githubusercontent.com/d31c6f7a7d9db7fb950ddc7e1efffefbe85c52fe171b3145dce930271ad1adfa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c61726176656c2d656e736f2f6c6f636b61626c652d6d6f64656c732e737667)](https://github.com/laravel-enso/lockable-models/issues)[![Merge Requests](https://camo.githubusercontent.com/7741fb2bfdc964579064f6a4a7be5738e833e881ba72bc986ff1d9dbecd91c75/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6c61726176656c2d656e736f2f6c6f636b61626c652d6d6f64656c732e737667)](https://github.com/laravel-enso/lockable-models/pulls)

Description
-----------

[](#description)

Lockable Models provides short-lived edit locks for Eloquent models.

It is meant for collaborative backoffice flows where a record should be protected from concurrent edits while a user is working on it. The package offers a base lockable model, a base lock model, middleware that prevents actions on already locked models, and a terminate middleware that releases successful edit locks automatically.

Locks are user-aware, expire automatically after a configurable number of minutes, and allow the locking user to continue working on the same record while blocking everyone else.

The package depends on `laravel-enso/users` for lock ownership and display identity. It does not depend on `people` directly; the lock message uses the user model's public display API.

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

[](#installation)

Install the package:

```
composer require laravel-enso/lockable-models
```

If needed, publish the config:

```
php artisan vendor:publish --tag=lockable-models-config
```

Default configuration:

```
return [
    'lock_duration' => 5,
];
```

To use the package, your implementation typically needs:

- a model extending `LockableModel`
- a related lock model extending `ModelLock`
- a one-to-one table for storing the current lock
- the request middleware pair on routes that edit the model

Features
--------

[](#features)

- Creates user-specific temporary locks for editable models.
- Prevents concurrent actions when another user holds a non-expired lock.
- Allows the same user to continue editing an already locked model.
- Automatically expires stale locks after the configured duration.
- Releases locks automatically after successful requests.
- Provides reusable abstract models for both the lockable record and the lock record.

Usage
-----

[](#usage)

Create a lockable model by extending the base class:

```
use LaravelEnso\LockableModels\Models\LockableModel;

class Order extends LockableModel
{
}
```

Create a related lock model:

```
use LaravelEnso\LockableModels\Models\ModelLock;

class OrderLock extends ModelLock
{
}
```

Protect editing routes with the middleware pair:

```
Route::middleware([
    PreventActionOnLockedModels::class,
    UnlocksModelOnTerminate::class,
])->group(function () {
    // edit routes
});
```

Manually acquire and release a lock:

```
$order->lockFor($user);
$order->unlockFor($user);
```

::: warning Note `UnlocksModelOnTerminate` only releases locks when the response status is `200`.

If a request fails or returns a different success status, the lock remains active until it is explicitly released or it expires. :::

API
---

[](#api)

### Models

[](#models)

`LaravelEnso\LockableModels\Models\LockableModel`

Public methods:

- `lock()`
- `lockFor(User $user): void`
- `unlockFor(User $user): void`
- `lockForMinutes(): int`

`LaravelEnso\LockableModels\Models\ModelLock`

Public methods:

- `expired(): bool`
- `allowed(User $user): bool`
- `user(): BelongsTo`
- `scopeIsExpired(Builder $query): Builder`

### Middleware

[](#middleware)

- `PreventActionOnLockedModels`
- `UnlocksModelOnTerminate`

Behavior:

- detects route parameters that are instances of `LockableModel`
- blocks the request if a valid lock belongs to another user
- acquires the lock for the current user before handling the request
- releases the lock on terminate for successful `200` responses

### Exceptions

[](#exceptions)

- `LaravelEnso\LockableModels\Exceptions\ModelLockException`

Current lock failure message:

- `Locked by: :user`

Depends On
----------

[](#depends-on)

Required Enso packages:

- [`laravel-enso/core`](https://docs.laravel-enso.com/backend/core.html) [↗](https://github.com/laravel-enso/core)
- [`laravel-enso/helpers`](https://docs.laravel-enso.com/backend/helpers.html) [↗](https://github.com/laravel-enso/helpers)
- [`laravel-enso/migrator`](https://docs.laravel-enso.com/backend/migrator.html) [↗](https://github.com/laravel-enso/migrator)
- [`laravel-enso/users`](https://docs.laravel-enso.com/backend/users.html) [↗](https://github.com/laravel-enso/users)

Framework dependency:

- [`laravel/framework`](https://github.com/laravel/framework) [↗](https://github.com/laravel/framework)

Contributions
-------------

[](#contributions)

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance91

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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

Every ~105 days

Total

5

Last Release

42d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16073274?v=4)[Adrian Ocneanu](/maintainers/aocneanu)[@aocneanu](https://github.com/aocneanu)

---

Top Contributors

[![aocneanu](https://avatars.githubusercontent.com/u/16073274?v=4)](https://github.com/aocneanu "aocneanu (6 commits)")[![vmcvlad](https://avatars.githubusercontent.com/u/37445394?v=4)](https://github.com/vmcvlad "vmcvlad (3 commits)")

---

Tags

laravel-ensolockable-modelslaravel-lockable-models

### Embed Badge

![Health badge](/badges/laravel-enso-lockable-models/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-enso-lockable-models/health.svg)](https://phpackages.com/packages/laravel-enso-lockable-models)
```

###  Alternatives

[laravel-enso/localisation

Language and translation management for Laravel Enso

1362.3k11](/packages/laravel-enso-localisation)[laravel-enso/core

The backend shell of a Laravel Enso application

3464.9k199](/packages/laravel-enso-core)[laravel-enso/data-import

Excel Importer dependency for Laravel Enso

2043.6k6](/packages/laravel-enso-data-import)[laravel-enso/tutorials

Tutorial management backend for Laravel Enso

1140.4k](/packages/laravel-enso-tutorials)[laravel-enso/tables

Server-side data tables and export backend for Laravel Enso

63254.7k81](/packages/laravel-enso-tables)[laravel-enso/comments

Comments Manager for Laravel Enso

1140.5k1](/packages/laravel-enso-comments)

PHPackages © 2026

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