diff --git a/.gitignore b/.gitignore index e69de29..ff72e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +/composer.lock +/vendor diff --git a/composer.json b/composer.json index 5097023..5e75b65 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ }, "require": { "php": ">=5.5.9", - "illuminate/database": "5.*", - "illuminate/support": "5.*" + "illuminate/database": "~5.2", + "illuminate/support": "~5.2", + "illuminate/console": "~5.2" } } diff --git a/readme.md b/readme.md index 1405e83..00f553e 100644 --- a/readme.md +++ b/readme.md @@ -35,28 +35,28 @@ class Post extents Model } ``` -All models that use the trait should implement the abstract function -```asbstract public function by()``` which should return any string. +All models that use the trait must implement ```abstract public function by()``` which returns any string. +This function can be used to save any additional attributes such as the owner of the change. -This function can be used to save any additional attributes such as the -owner of the change. - -Get the state of a record at a specific data/time. +###Get the state of a record at a specific data/time. ```php - Post::at('58781813')->find(1); +Post::at('58781813')->find(1); ``` -Get the state of a record using a query string. +###Get the state of a record using a query string. URL: ```timetravel.app/posts/1?at=58781813``` ```php - Post::find(1); +Post::find(1); +``` + +###Get a model with revisions +```php +Post::with('revisions')->first(); ``` -You can clear the audits table records that are older than a specified range. +###You can clear the audits table records that are older than a specified range. ```php artisan time-traveller:clear```. This will read the config file and clear records that are older than the configured number of days. ## Todo -- Artisan command to clear revisions. -- Return revisions as models/collections - not as nested relations. -- Documentation. +- Artisan command to clear revisions. \ No newline at end of file diff --git a/src/Console/ClearRevisionsCommand.php b/src/Console/ClearRevisionsCommand.php new file mode 100644 index 0000000..09fdf0e --- /dev/null +++ b/src/Console/ClearRevisionsCommand.php @@ -0,0 +1,39 @@ +confirm('Do you wish to continue? [y|N]')) { + $date->modify("-$interval days")->format('Y-m-d H:i:s'); + return Revision::where('created_at', '<=', $date)->delete(); + } + } +} \ No newline at end of file diff --git a/src/Models/Revision.php b/src/Models/Revision.php index 1f68acb..043cebf 100644 --- a/src/Models/Revision.php +++ b/src/Models/Revision.php @@ -31,7 +31,7 @@ class Revision extends Model /** * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ - public function auditable() + public function revisionable() { return $this->morphTo(); } diff --git a/src/Scopes/TimeTravel.php b/src/Scopes/TimeTravel.php index ba9d660..2c57b8b 100644 --- a/src/Scopes/TimeTravel.php +++ b/src/Scopes/TimeTravel.php @@ -36,6 +36,8 @@ public function revisions() } /** + * Get the revisions at the given timestamp + * * @param $query * @param $time * @return mixed diff --git a/src/Scopes/TimeTravelScope.php b/src/Scopes/TimeTravelScope.php index d40f6c9..b012517 100644 --- a/src/Scopes/TimeTravelScope.php +++ b/src/Scopes/TimeTravelScope.php @@ -3,9 +3,9 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\ScopeInterface; +use Illuminate\Database\Eloquent\Scope; -class TimeTravelScope implements ScopeInterface +class TimeTravelScope implements Scope { /** * Apply the scope to a given Eloquent query builder. @@ -18,17 +18,4 @@ public function apply(Builder $builder, Model $model) { $model->scopeAt($builder, request()->get(config('timetraveller.at'))); } - - /** - * Remove the scope from the given Eloquent query builder. - * - * @param \Illuminate\Database\Eloquent\Builder $builder - * @param \Illuminate\Database\Eloquent\Model $model - * - * @return void - */ - public function remove(Builder $builder, Model $model) - { - // TODO: Implement remove() method. - } } \ No newline at end of file