Skip to content

Commit

Permalink
Merge pull request #61 from nonoesp/master
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
nonoesp authored Apr 30, 2020
2 parents 9c0fb2d + cbc1b05 commit 172b787
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Versionable
## Easy to use Model versioning for Laravel

## Laravel Model versioning made easy

![image](http://img.shields.io/packagist/v/mpociot/versionable.svg?style=flat)
![image](http://img.shields.io/packagist/l/mpociot/versionable.svg?style=flat)
Expand All @@ -22,18 +23,16 @@ $oldModel = Version::find(100)->getModel();

## Installation

In order to add Versionable to your project, just add

"mpociot/versionable": "~3.0"

to your composer.json. Then run `composer install` or `composer update`.
You can install via composer:

Or run `composer require mpociot/versionable ` if you prefere that.
```
composer require mpociot/versionable
```

Run the migrations to create the "versions" table that will hold all version information.
Run the migrations.

```bash
php artisan migrate --path=vendor/mpociot/versionable/src/migrations
```
php artisan migrate
```

<a name="usage" />
Expand All @@ -49,6 +48,7 @@ class Content extends Model {

}
```

That's it!

Every time you update your model, a new version containing the previous attributes will be stored in your database.
Expand Down Expand Up @@ -123,7 +123,6 @@ The diff method takes a version model as an argument. This defines the version t
*/
$diff = $page->previousVersion()->diff();


/**
* Create a diff against a specific version
*/
Expand Down Expand Up @@ -154,7 +153,6 @@ You can also revert to a specific version ID of a model using:

```php
$revertedModel = Version::find( $version_id )->revert();

```

<a name="disableVersioning" />
Expand Down Expand Up @@ -187,9 +185,8 @@ To use a different table to store version for some model we have to change the t
class MyModelVersion extends Version
{
$table = 'mymodel_versions';
...
// ...
}

```

In the model that you want it use this specific versions table, use the `VersionableTrait` Trait and add the property `$versionClass` with value the specific version model.
Expand All @@ -199,9 +196,8 @@ class MyModel extends Eloquent
{
use VersionableTrait ;
protected $versionClass = MyModelVersion::class ;
...
// ...
}

```

And do not forget to create a migration for this versions table, exactly as the default versions table.
Expand Down

0 comments on commit 172b787

Please sign in to comment.