Skip to content

Commit

Permalink
Laravel 9
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Feb 10, 2022
1 parent 11534c7 commit ac67fe6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,47 @@
<a href="https://packagist.org/packages/overtrue/laravel-versionable"><img src="https://poser.pugx.org/overtrue/laravel-versionable/license" alt="License"></a>
</p>


It's a minimalist way to make your model support version history, and it's very simple to roll back to the specified version.

[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue)


## Requirement

1. PHP >= 7.4
2. laravel/framework >= 5.8|6.0|7.0
1. PHP >= 8.0.2
2. laravel/framework >= 9.0

## Features
- Keep the specified number of versions.
- Whitelist and blacklist for versionable attributes.
- Easily roll back to the specified version.
- Record only changed attributes.
- Easy to customize.

- Keep the specified number of versions.
- Whitelist and blacklist for versionable attributes.
- Easily roll back to the specified version.
- Record only changed attributes.
- Easy to customize.

## Installing

```shell
$ composer require overtrue/laravel-versionable -vvv
composer require overtrue/laravel-versionable -vvv
```

Optional, you can publish the config file:

```bash
$ php artisan vendor:publish --provider="Overtrue\LaravelVersionable\ServiceProvider" --tag=config
php artisan vendor:publish --provider="Overtrue\LaravelVersionable\ServiceProvider" --tag=config
```

And if you want to custom the migration of the versions table, you can publish the migration file to your database path:

```bash
$ php artisan vendor:publish --provider="Overtrue\LaravelVersionable\ServiceProvider" --tag=migrations
php artisan vendor:publish --provider="Overtrue\LaravelVersionable\ServiceProvider" --tag=migrations
```

> After you published the migration files, please update `'migrations' => false` in the config file `config/versionable.php` to disable load the package migrations.
> After you published the migration files, please update `'migrations' => false` in the config file `config/versionable.php` to disable load the package migrations.
Then run this command to create a database migration:

```bash
$ php artisan migrate
php artisan migrate
```

## Usage
Expand All @@ -67,14 +65,14 @@ use Overtrue\LaravelVersionable\Versionable;
class Post extends Model
{
use Versionable;

/**
* Versionable attributes
*
* @var array
*/
protected $versionable = ['title', 'content'];

<...>
}
```
Expand Down Expand Up @@ -113,10 +111,11 @@ $post->getVersion(3)->revert();

$post->revertToVersion(3);
```

#### Reversion without saving

```php
$version = $post->versions()->first();
$version = $post->versions()->first();

$post = $version->revertWithoutSaving();
```
Expand All @@ -141,7 +140,6 @@ $post->forceRemoveAllVersions();
$post->restoreTrashedVersion($id);
```


### Temporarily disable versioning

```php
Expand All @@ -160,21 +158,21 @@ Post::withoutVersion(function () use ($post) {

You can set the following different version policies through property `protected $versionStrategy`:

- `Overtrue\LaravelVersionable::DIFF` - Version content will only contain changed attributes (Default Strategy).
- `Overtrue\LaravelVersionable::SNAPSHOT` - Version content will contain all versionable attributes values.
- `Overtrue\LaravelVersionable::DIFF` - Version content will only contain changed attributes (Default Strategy).
- `Overtrue\LaravelVersionable::SNAPSHOT` - Version content will contain all versionable attributes values.

## :heart: Sponsor me
## :heart: Sponsor me

[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)

如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue)


## Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue)

## Contributing

You can contribute in one of three ways:
Expand Down
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"name": "overtrue/laravel-versionable",
"description": "Make Laravel model versionable.",
"require": {
"php": "^8.0",
"php": "^8.0.2",
"laravel/framework": "^9.0",
"sebastian/diff": "^3.0|^4.0",
"doctrine/dbal": "^2.12|^3.0"
"sebastian/diff": "^4.0",
"doctrine/dbal": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^8.1|^9.0",
"orchestra/testbench": "^5.3|^6.0",
"friendsofphp/php-cs-fixer": "^2.16",
"brainmaestro/composer-git-hooks": "^2.8",
"phpunit/phpunit": "^9.0",
"orchestra/testbench": "^7.0",
"friendsofphp/php-cs-fixer": "^3.6",
"mockery/mockery": "^1.4"
},
"autoload": {
Expand Down Expand Up @@ -62,5 +61,10 @@
"check-style": "Run style checks (only dry run - no fixing!).",
"fix-style": "Run style checks and fix violations."
},
"license": "MIT"
"license": "MIT",
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true
}
}
}

0 comments on commit ac67fe6

Please sign in to comment.