定制 laravel-enso/versions 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel-enso/versions

最新稳定版本:2.0.6

Composer 安装命令:

composer require laravel-enso/versions

包简介

Prevents update conflicts using the optimistic lock pattern in Laravel

README 文档

README

License Stable Downloads PHP Issues Merge Requests

Description

Versions prevents concurrent-update conflicts through an optimistic-lock field on Eloquent models.

The package increments a version column on each update, checks the persisted version under a database lock before writing, and throws an HTTP 409 conflict when the record was modified after it was loaded.

It can work independently of the Laravel Enso ecosystem.

Installation

Install the package:

composer require laravel-enso/versions

Add the trait to a model that has a version column:

use Illuminate\Database\Eloquent\Model;
use LaravelEnso\Versions\Traits\Versions;

class Invoice extends Model
{
    use Versions;
}

The trait expects a version integer column by default. To use another column name, define a protected $versioningAttribute property on the model.

Features

  • Sets the version column to 1 when creating a model.
  • Starts a database transaction before updates and checks the persisted version under a lock.
  • Increments the version automatically when the update is accepted.
  • Throws a ConflictHttpException when another process already changed the record.

Usage

Manual version check:

$invoice->checkVersion($request->integer('version'));

Custom version column:

class Invoice extends Model
{
    use Versions;

    protected string $versioningAttribute = 'lock_version';
}

If the check fails, the package throws LaravelEnso\\Versions\\Exceptions\\Version, which extends Symfony's ConflictHttpException.

API

Trait

  • LaravelEnso\\Versions\\Traits\\Versions

Main methods:

  • checkVersion(?int $version = null): void

Lifecycle hooks:

  • bootVersions()

Exception

  • LaravelEnso\\Versions\\Exceptions\\Version

Factory method:

  • Version::recordModified(string $class)

Depends On

This package has no Enso package dependencies and can be used independently.

Contributions

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

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

License

MIT

统计信息

  • 总下载量: 9.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固