PHPackages                             lowerrocklabs/laravel-lockable - 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. lowerrocklabs/laravel-lockable

ActiveLibrary

lowerrocklabs/laravel-lockable
==============================

Laravel Lockable provides traits to allow for models to be locked

1.21(3y ago)72933[2 issues](https://github.com/LowerRockLabs/laravel-lockable/issues)[5 PRs](https://github.com/LowerRockLabs/laravel-lockable/pulls)MITPHPPHP ^7.3|^8.0CI failing

Since Oct 2Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/LowerRockLabs/laravel-lockable)[ Packagist](https://packagist.org/packages/lowerrocklabs/laravel-lockable)[ Docs](https://github.com/lowerrocklabs/laravel-lockable)[ RSS](/packages/lowerrocklabs-laravel-lockable/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (13)Versions (20)Used By (0)

Laravel Lockable provides traits to allow for models to be locked
=================================================================

[](#laravel-lockable-provides-traits-to-allow-for-models-to-be-locked)

[![Latest Version on Packagist](https://camo.githubusercontent.com/25cda27b96e911ec7087af4e31bcf367793e6babb3374264c03560b8b7225f01/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f776572726f636b6c6162732f6c61726176656c2d6c6f636b61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lowerrocklabs/laravel-lockable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/48a8dbc616706aa24733c2d5d65b00cf7b3a1cb686c0ce126d9bfbb520faa2f3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c6f776572726f636b6c6162732f6c61726176656c2d6c6f636b61626c652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/lowerrocklabs/laravel-lockable/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ba335e79d6d4a4330763d0aa2109e4cc5c8a75d89b5a5537bf944c1e32092dee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c6f776572726f636b6c6162732f6c61726176656c2d6c6f636b61626c652f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/lowerrocklabs/laravel-lockable/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![](https://camo.githubusercontent.com/208f3708584e3ffda22c32b7bbaa90cdb2f5cd24438d7e00ee91c35c01381e48/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64653432653366303564306362313632396338642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/LowerRockLabs/laravel-lockable/maintainability)[![](https://camo.githubusercontent.com/86d5528068cacdf42520c0f79ccb6d17cf54a71ff994fcc4122c9af587773fbe/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64653432653366303564306362313632396338642f746573745f636f766572616765)](https://codeclimate.com/github/LowerRockLabs/laravel-lockable/test_coverage)[![Total Downloads](https://camo.githubusercontent.com/19057138fab73ccf1f6a994023f13d40ceed46a3a1d57008e58f93e07c46ba64/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f776572726f636b6c6162732f6c61726176656c2d6c6f636b61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lowerrocklabs/laravel-lockable)

This model allows for on-demand locking of models. You can integrate this with your permissions methodology of choice, or leave it stand-alone. This package allows you to determine whether a particular instance of a model is Locked or Not. Or it will independently prevent updating of a model instance.

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

[](#installation)

> **Requires \[PHP 7.3+ or 8.0+\] and \[Laravel 8.x or 9.x\] ( or )**

You can install the package via composer:

```
composer require lowerrocklabs/laravel-lockable
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="laravel-lockable-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-lockable-config"
```

This is the contents of the published config file, which controls the global lock duration, this is customisable on a per-model basis (see below).

```
return [
    // Name of the Table containing the locks
    'locks_table' => 'model_locks',

     // Name of the Table containing the lock watchers
    'lock_watchers_table' => 'model_lock_watchers',

    // Enable retrieval of lock status on retrieving a model
    'get_locked_on_retrieve' => true,

    // Prevent updating if a model is locked by another user
    'prevent_updating' => true,

    // Time in Seconds For Lock To Persist
    'duration' => '3600',
];
```

Usage
-----

[](#usage)

#### Model Configuration

[](#model-configuration)

In the Model(s) that you wish to be lockable, add the IsLockable Trait

```
use LowerRockLabs\Lockable\Traits\IsLockable;
```

and then set the Trait

```
use IsLockable;
```

#### In Your Component/Controller

[](#in-your-componentcontroller)

Then use the acquireLock function to attempt to acquire a lock on the model, it will return false if there is an existing lock.

```
acquireLock()
```

You can override the existing lock by calling the releaseLock() function before acquireLock(), if you are using a permissions-based approach, it is suggested that you restrict this to approriate users.

```
releaseLock()
```

You can tell if a lock exists as follows, this will acquire the lock if one does not exist.

```
isLocked()
```

You can send a Broadcast to the user holding the lock with the following

```
requestLock()
```

#### Lock Duration

[](#lock-duration)

You can override the default Lock Duration (in seconds) which is taken from the configuration on a per-model basis by setting the following in your Model, for example, the following would limit the duration of a lock to 600 seconds.

```
public $modelLockDuration = "600";
```

Locks will clear when the Duration has expired, and an attempt is made to access the Model, or you can call the commands below, or add them to a schedule (as you see fit).

#### Commands

[](#commands)

**To Flush Expired Locks**

```
php artisan locks:flushexpired
```

**To Flush All Locks**

```
php artisan locks:flushall
```

#### Events

[](#events)

Two Events will be fired during the Lock process, that can be used to fire Notifications or Logs if desired **On Model Locking**

```
LowerRockLabs\Lockable\Events\ModelWasLocked;
```

and **On Model UnLocking**

```
LowerRockLabs\Lockable\Events\ModelWasUnLocked;
```

An additional event will be fired when a user requests the release of the lock and **On Model UnLocking**

```
LowerRockLabs\Lockable\Events\ModelUnlockRequested;
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Joe](https://github.com/LowerRockLabs)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 86% of packages

Maintenance46

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 68.2% 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 ~101 days

Recently: every ~151 days

Total

7

Last Release

659d ago

PHP version history (3 changes)1.0PHP ^8.1

1.1PHP ^8.0

1.2PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad9b77732ba3e0d2541c10253825fcd51311362305ca4700cc74d0b6ec5c9b4f?d=identicon)[lrljoe](/maintainers/lrljoe)

---

Top Contributors

[![lrljoe](https://avatars.githubusercontent.com/u/104938042?v=4)](https://github.com/lrljoe "lrljoe (135 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (37 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (26 commits)")

---

Tags

laravellaravel-packagelocklockingmodellaravelLowerRockLabslaravel-lockable

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[rupadana/filament-api-service

A simple api service for supporting filamentphp

20399.6k7](/packages/rupadana-filament-api-service)[spatie/laravel-authorize

A middleware to check authorization

20625.6k1](/packages/spatie-laravel-authorize)[api-platform/laravel

API Platform support for Laravel

58113.6k3](/packages/api-platform-laravel)[marcogermani87/filament-cookie-consent

Easy cookie consent integrations for Filament

1916.7k](/packages/marcogermani87-filament-cookie-consent)[laravel-latam/spanish

Spanish Package for Laravel

124.2k](/packages/laravel-latam-spanish)

PHPackages © 2026

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