PHPackages                             hyperlink/laravel-model-locking - 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. hyperlink/laravel-model-locking

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

hyperlink/laravel-model-locking
===============================

Wordpress like locking feature for Laravel-Models.

0.3.0(3y ago)26.3k↓50%1MITPHPPHP ^8.0

Since Jan 5Pushed 2y ago3 watchersCompare

[ Source](https://github.com/hyperlinkgroup/laravel-model-locking)[ Packagist](https://packagist.org/packages/hyperlink/laravel-model-locking)[ GitHub Sponsors](https://github.com/hyperlinkgroup)[ RSS](/packages/hyperlink-laravel-model-locking/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (19)Used By (0)

Laravel Model Locking by [HYPERLINK GROUP](https://github.com/orgs/hyperlinkgroup)
==================================================================================

[](#laravel-model-locking-by-hyperlink-group)

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

[](#installation)

You can install the package via composer:

```
composer require hyperlink/laravel-model-locking
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Hylk\Locking\ModelLockingServiceProvider" --tag="model-locking-config"
```

You can publish the translation files with:

```
php artisan vendor:publish --provider="Hylk\Locking\ModelLockingServiceProvider" --tag="model-locking-translations"
```

You can publish the vue-components via:

```
php artisan vendor:publish --provider="Hylk\Locking\ModelLockingServiceProvider" --tag="model-locking-vue"
```

Usage
-----

[](#usage)

### Setting up your models

[](#setting-up-your-models)

Within a model just use the `IsLockable`-Trait.

```
class Post extends Model {
    use \Hylk\ModelLocking\IsLockable;

    ...
}
```

Additionally you have to extend the database-tables for the Model.

```
return new class extends Migration {
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->lockfields();
        });
    }

    public function down()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->dropLockfields();
        });
    }
}
```

### simple Model-Locking

[](#simple-model-locking)

If you want just a simple version of the locking, just use the Traits methods within your controller. `HEARTBEAT_LOCK_DURATION` should be set to something like 15 minutes (900 seconds).

```
class PostController {
    public function show(Post $post) {
      $post->lock();
    }

    public function update(Request $request, Post $post) {
      $post->update($request->all());
      $post->unlock();
    }
}
```

To make sure no locks are missed you should use the `locking:release` Artisan command in your scheduler. Additionally, you should publish the config and set the lock duration to around 15 minutes.

### Model-Locking by heartbeat (Vue)

[](#model-locking-by-heartbeat-vue)

The more advanced approach is to handle the locks via a heartbeat. This only works for `Vue` and `axios`.

1. Publish the vue-components
2. register the global HeartbeatManager ```
    import Vue from 'vue';
    import HeartbeatManager from './vendor/hylk/laravel-model-locking/heartbeat-manager';
    ...
    window.axios = require('axios');
    ...
    Vue.use(HeartbeatManager);
    ```
3. register the Listener-Components
    1. for index-pages

    ```

            ...

    ```

    Handle the wished behavior like showing the current locker by the `lock` event and delete this information on the `unlock`-event. ```
    ...
       Locked by {{ getLock(model_id).locked_by.name }}
    ...
    ```
4. register the LockRefresher on your Edit-form. ```

          ...

    ```

    The `lost`-Event shows if the component tries to render if the model is locked by another user than the logged in.

### Environment variables

[](#environment-variables)

VariableDefaultDescription`HEARTBEAT_LOCK_DURATION`70The time in seconds a model is locked.`MIX_HEARTBEAT_REFRESH`60The time in seconds between the heartbeats. Should be a multiple of the `MIX_HEARTBEAT_STATUS`-interval.`MIX_HEARTBEAT_STATUS`30The time in seconds between the heartbeats for status-request (index-Listener).`MIX_HEARTBEAT_ENABLED`trueActivates or deactivates the heartbeats.### config

[](#config)

Beside the environment variables, there is a `middleware` key to determine the middleware(s) used by the heartbeat-route. Default it's set to `api`.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.4% 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 ~3 days

Total

16

Last Release

1186d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/69b181264e5c9a7d89c80721247a92aae0cf9a970e65e55a31cb77cc62546e1d?d=identicon)[hyperlink](/maintainers/hyperlink)

---

Top Contributors

[![red-freak](https://avatars.githubusercontent.com/u/66564761?v=4)](https://github.com/red-freak "red-freak (38 commits)")[![Katalam](https://avatars.githubusercontent.com/u/39590058?v=4)](https://github.com/Katalam "Katalam (1 commits)")

### Embed Badge

![Health badge](/badges/hyperlink-laravel-model-locking/health.svg)

```
[![Health](https://phpackages.com/badges/hyperlink-laravel-model-locking/health.svg)](https://phpackages.com/packages/hyperlink-laravel-model-locking)
```

###  Alternatives

[spatie/laravel-settings

Store your application settings

1.5k5.9M72](/packages/spatie-laravel-settings)[spatie/laravel-personal-data-export

Create personal data downloads in a Laravel app

550543.8k8](/packages/spatie-laravel-personal-data-export)[spatie/laravel-screenshot

Take screenshots of web pages in Laravel apps

7615.9k2](/packages/spatie-laravel-screenshot)[protonemedia/laravel-task-runner

Write Shell scripts like Blade Components and run them locally or on a remote server

1325.5k1](/packages/protonemedia-laravel-task-runner)

PHPackages © 2026

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