Skip to content

Commit

Permalink
Merge pull request #141 from VentureCraft/develop
Browse files Browse the repository at this point in the history
Remove duplicate booting in L5
  • Loading branch information
duellsy committed May 31, 2015
2 parents ebb08e6 + b497444 commit eeaa0ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,18 @@ php artisan migrate --package=venturecraft/revisionable
### The new, trait based implementation

For any model that you want to keep a revision history for, include the revisionable namespace and use the `RevisionableTrait` in your model, e.g.,
If you are using another bootable trait the be sure to override the boot method in your model;

```php
namespace MyApp\Models;

class Article extends Eloquent {
use \Venturecraft\Revisionable\RevisionableTrait;

public static function boot()
{
parent::boot();
}
}
```

Expand Down
19 changes: 15 additions & 4 deletions src/Venturecraft/Revisionable/RevisionableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@ trait RevisionableTrait
*/
protected $dirtyData = array();

/**
* Ensure that the bootRevisionableTrait is called only
* if the current installation is a laravel 4 installation
* Laravel 5 will call bootRevisionableTrait() automatically
*/
public static function boot()
{
parent::boot();

if(!method_exists(get_called_class(), 'bootTraits')){
static::bootRevisionableTrait();
}
}

/**
* Create the event listeners for the saving and saved events
* This lets us save revisions whenever a save is made, no matter the
* http method.
*
*/
public static function boot()
public static function bootRevisionableTrait()
{
parent::boot();

static::saving(function ($model) {
$model->preSave();
});
Expand All @@ -45,7 +57,6 @@ public static function boot()
$model->preSave();
$model->postDelete();
});

}

public function revisionHistory()
Expand Down

0 comments on commit eeaa0ad

Please sign in to comment.