@@ -64,10 +64,10 @@ |
||
64 | 64 | public function revert() |
65 | 65 | { |
66 | 66 | $model = $this->getModel(); |
67 | - unset( $model->{$model->getCreatedAtColumn()} ); |
|
68 | - unset( $model->{$model->getUpdatedAtColumn()} ); |
|
67 | + unset($model->{$model->getCreatedAtColumn()} ); |
|
68 | + unset($model->{$model->getUpdatedAtColumn()} ); |
|
69 | 69 | if (method_exists($model, 'getDeletedAtColumn')) { |
70 | - unset( $model->{$model->getDeletedAtColumn()} ); |
|
70 | + unset($model->{$model->getDeletedAtColumn()} ); |
|
71 | 71 | } |
72 | 72 | $model->save(); |
73 | 73 | return $model; |
@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace Mpociot\Versionable; |
3 | 3 | |
4 | 4 | use Illuminate\Support\Facades\Config; |
5 | -use Illuminate\Database\Eloquent\Model as Eloquent; |
|
6 | 5 | use Illuminate\Database\Eloquent\Model; |
7 | 6 | |
8 | 7 | /** |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public static function bootVersionableTrait() |
73 | 73 | { |
74 | - static::saving(function ($model) { |
|
74 | + static::saving(function($model) { |
|
75 | 75 | $model->versionablePreSave(); |
76 | 76 | }); |
77 | 77 | |
78 | - static::saved(function ($model) { |
|
78 | + static::saved(function($model) { |
|
79 | 79 | $model->versionablePostSave(); |
80 | 80 | }); |
81 | 81 | |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * We'll save new versions on updating and first creation |
148 | 148 | */ |
149 | 149 | if ( |
150 | - ( $this->versioningEnabled === true && $this->updating && $this->isValidForVersioning() ) || |
|
151 | - ( $this->versioningEnabled === true && !$this->updating ) |
|
150 | + ($this->versioningEnabled === true && $this->updating && $this->isValidForVersioning()) || |
|
151 | + ($this->versioningEnabled === true && !$this->updating) |
|
152 | 152 | ) { |
153 | 153 | // Save a new version |
154 | 154 | $version = new Version(); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $version->user_id = $this->getAuthUserId(); |
158 | 158 | $version->model_data = serialize($this->getAttributes()); |
159 | 159 | |
160 | - if (!empty( $this->reason )) { |
|
160 | + if (!empty($this->reason)) { |
|
161 | 161 | $version->reason = $this->reason; |
162 | 162 | } |
163 | 163 | |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | */ |
173 | 173 | private function isValidForVersioning() |
174 | 174 | { |
175 | - $dontVersionFields = isset( $this->dontVersionFields ) ? $this->dontVersionFields : []; |
|
176 | - $removeableKeys = array_merge($dontVersionFields, [$this->getUpdatedAtColumn()]); |
|
175 | + $dontVersionFields = isset($this->dontVersionFields) ? $this->dontVersionFields : [ ]; |
|
176 | + $removeableKeys = array_merge($dontVersionFields, [ $this->getUpdatedAtColumn() ]); |
|
177 | 177 | |
178 | 178 | if (method_exists($this, 'getDeletedAtColumn')) { |
179 | - $removeableKeys[] = $this->getDeletedAtColumn(); |
|
179 | + $removeableKeys[ ] = $this->getDeletedAtColumn(); |
|
180 | 180 | } |
181 | 181 | |
182 | - return ( count(array_diff_key($this->versionableDirtyData, array_flip($removeableKeys))) > 0 ); |
|
182 | + return (count(array_diff_key($this->versionableDirtyData, array_flip($removeableKeys))) > 0); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -5,30 +5,30 @@ |
||
5 | 5 | |
6 | 6 | class AddReason extends Migration { |
7 | 7 | |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function up() |
|
14 | - { |
|
15 | - Schema::table('versions', function(Blueprint $table) |
|
16 | - { |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function up() |
|
14 | + { |
|
15 | + Schema::table('versions', function(Blueprint $table) |
|
16 | + { |
|
17 | 17 | $table->string('reason', 100)->nullable()->after('model_data'); |
18 | - }); |
|
19 | - } |
|
18 | + }); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Reverse the migrations. |
|
23 | - * |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function down() |
|
27 | - { |
|
28 | - Schema::table('versions', function(Blueprint $table) |
|
29 | - { |
|
21 | + /** |
|
22 | + * Reverse the migrations. |
|
23 | + * |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function down() |
|
27 | + { |
|
28 | + Schema::table('versions', function(Blueprint $table) |
|
29 | + { |
|
30 | 30 | $table->dropColumn('reason'); |
31 | - }); |
|
32 | - } |
|
31 | + }); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | } |
@@ -5,32 +5,32 @@ |
||
5 | 5 | |
6 | 6 | class CreateVersionsTable extends Migration { |
7 | 7 | |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function up() |
|
14 | - { |
|
15 | - Schema::create('versions', function(Blueprint $table) |
|
16 | - { |
|
17 | - $table->increments('version_id'); |
|
18 | - $table->integer('versionable_id'); |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function up() |
|
14 | + { |
|
15 | + Schema::create('versions', function(Blueprint $table) |
|
16 | + { |
|
17 | + $table->increments('version_id'); |
|
18 | + $table->integer('versionable_id'); |
|
19 | 19 | $table->text('versionable_type'); |
20 | - $table->integer('user_id')->nullable(); |
|
21 | - $table->binary('model_data'); |
|
22 | - $table->timestamps(); |
|
23 | - }); |
|
24 | - } |
|
20 | + $table->integer('user_id')->nullable(); |
|
21 | + $table->binary('model_data'); |
|
22 | + $table->timestamps(); |
|
23 | + }); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Reverse the migrations. |
|
28 | - * |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function down() |
|
32 | - { |
|
33 | - Schema::drop('versions'); |
|
34 | - } |
|
26 | + /** |
|
27 | + * Reverse the migrations. |
|
28 | + * |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function down() |
|
32 | + { |
|
33 | + Schema::drop('versions'); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |