ervinne/nw-cms-version
Composer 安装命令:
composer require ervinne/nw-cms-version
包简介
Enables Laravel model version controlled fields.
README 文档
README
This package enables tagging in Laravel models called versions. Versions allow different values at specified fields in a model.
Installation
Require the package in your composer.json and update your dependencies:
$ composer require "ervinne/nw-cms-version:v1.0.0"
Then add the service provider in your config/app.php providers array:
Ervinne\CMSVersion\Providers\CMSVersionServiceProvider::class,
Register Commands
To allow the command for generating migrations out of models to be version controlled, add the GenerateCMSVersionMigrations class to the App\Console\Kernel $commands property:
/** * The Artisan commands provided by your application. * * @var array */ protected $commands = [ Ervinne\CMSVersion\Commands\GenerateCMSVersionMigrations::class ];
Configurations
You can set which models to "Version Control" on the config/cms-versions.php configuration file. Publish the config to create this configuration file. Note that you will need to publish as well to generate the required javascript files when you want to reflect version data on an already displaying form (more on that later):
$ php artisan vendor:publish --provider="Ervinne\CMSVersion\Providers\CMSVersionServiceProvider"
Set which models you want to version control in the config/cms-versions.php
'models' => [ [ 'table' => 'my_table', 'primary_key' => 'id', 'classpath' => \App\User::class, 'is_published_field' => 'my_is_published_field', 'is_published_value' => true, 'is_unpublished_value' => false, ], ],
Where table, primary_key, classpath is the table, primary key, and class path of the model you want to version control. is_published_field is the name of the field you want to version control inside that model, ex: is_published, is_active, etc. is_published_value is the value that needs to be set to consider the field as "published", is_unpublished_value is vice versa.
In case you want to version control multiple fields in 1 model, just duplicate the model entries in the models array with the same table, primary_key, and classpath.
Migrating the Models
To enable version control on the models, the user must migrate after configuration with the following command:
$ php artisan make:cmsvmigration
This will create a migration called create_cms_version_pivot_tables that will contain database changes based on the configuration in config/cms-versions.php. Migrate afterwards using the command:
$ php artisan migrate
Model Setup
Use the trait VersionControlled in your model to enable versioning functionalities:
... use Ervinne\CMSVersion\VersionControlled; class BannerSet extends Model { use VersionControlled; ...
Saving Model to a Version
Before you save a model, you need to save a version to save it to first:
CMSVersion::insert([ 'display_name' => 'Default', 'description' => 'Default Version', 'status' => 'Published' ]);
Save your model by specifying the id of the saved CMSVersion object in the model's version_id field then save using the method saveWithVersion().
$bannerSet = new BannerSet(); $bannerSet->version_id = $request->version_id; // assumes the version comes from the request $bannerSet->label = $request->label; $bannerSet->images_json = $request->banners; $bannerSet->is_published = $request->is_published; $bannerSet->saveWithVersion();
Version Status
Version status can be any string you want but "Published" is reserved and is set to signify that the version is the currently used version. If you try to save version controlled fields to a model set to a version that's not published then those changes wont save on the model itself but will be put in the version records only. If a version with model data is set to published it's data will be updated to the respective models.
ervinne/nw-cms-version 适用场景与选型建议
ervinne/nw-cms-version 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「version」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ervinne/nw-cms-version 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ervinne/nw-cms-version 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ervinne/nw-cms-version 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Versioning behaviour for eloquent models
Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.
Display a version number
PHP Version Manager for Windows CLI
Obtains the latest version release of Composer Packages from the Packagist API
Version management package for Laravel
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-13