cape-and-bay/versionable
最新稳定版本:v1.0.1
Composer 安装命令:
composer require cape-and-bay/versionable
包简介
Laravel Drafts tool for models
README 文档
README
⏱️ Make Laravel model versionable.
It's a minimalist way to make your model support version history, and it's very simple to roll back to the specified version.
Requirement
- PHP >= 8.1
- laravel/framework >= 9.0
Installing
composer require cape-and-bay/versionable -vvv
Then run this command to create a database migration:
php artisan migrate
Usage
Add CapeAndBay\Versionable\Versionable trait to the model that you want to be versioned:
use CapeAndBay\Versionable\Versionable; class Post extends Model { use Versionable; # Prevents versioning Post if only the "is_active" column is updated. protected array $dont_version = ['is_active']; }
Versions will be created on vensionable model saved.
$post = Post::create(['title' => 'version1', 'content' => 'version1 content']); $post->update(['title' => 'version2']);
You can prevent a new version of model from being created by return false on onNewVersionCreate. to use this method, your model must implement the VersionableInterface in conjunction with Versionable trait:
use CapeAndBay\Versionable\Versionable; use CapeAndBay\Versionable\VersionableInterface; use Illuminate\Database\Eloquent\Model; class User extends Model implements VersionableInterface { use Versionable; public function onNewVersionCreate(Model $model) : bool { // Create new version if email is not "skip@mail.com" return $model->email !== 'skip@mail.com'; } }
Get versions
$post->versions; // all versions $post->latestVersion(); // latest version $post->versions->first(); // first version
统计信息
- 总下载量: 2.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-18