Skip to content

Allow a user to lock a model and prevent anyone else editing it

License

Notifications You must be signed in to change notification settings

laravel-appkit/lockable

Repository files navigation

Eloquent Lockable

Latest Version on Packagist Build Status Quality Score Total Downloads Licence

Allows a user to acquire a lock on a model, which prevents anyone else from being able to edit it.

Installation

You can install the package via composer:

composer require laravel-appkit/lockable

Usage

Add the AppKit\Lockable\Traits\Lockable trait to the model you want to set locks on

Add a locked_by integer column to the corresponding table. This can also be done using the lockable method on the migration.

<?php

namespace App\Models;

use AppKit\Lockable\Traits\Lockable;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    use Lockable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title',
        'body'
    ];
}

Acquiring Locks

To acquire a lock on a model, call the acquireLock method on it.

$article->acquireLock();

Releasing Locks

To release the existing lock on a model, call the releaseLock method on it.

$article->releaseLock();

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email appkit-security@coutts.io instead of using the issue tracker.

Please see SECURITY for more details.

Credits

License

The MIT License (MIT). Please see License File for more information.