diff --git a/src/Listeners/Creating.php b/src/Listeners/Creating.php index efa2e9b..8432a0d 100644 --- a/src/Listeners/Creating.php +++ b/src/Listeners/Creating.php @@ -14,7 +14,7 @@ class Creating */ public function handle($model) { - if (! $model->isUserstamping()) { + if (! $model->isUserstamping() || is_null($model->getCreatedByColumn())) { return; } diff --git a/src/Listeners/Deleting.php b/src/Listeners/Deleting.php index dee6d44..0927197 100644 --- a/src/Listeners/Deleting.php +++ b/src/Listeners/Deleting.php @@ -14,7 +14,7 @@ class Deleting */ public function handle($model) { - if (! $model->isUserstamping()) { + if (! $model->isUserstamping() || is_null($model->getDeletedByColumn())) { return; } diff --git a/src/Listeners/Restoring.php b/src/Listeners/Restoring.php index 99ee318..b9309d9 100644 --- a/src/Listeners/Restoring.php +++ b/src/Listeners/Restoring.php @@ -12,7 +12,7 @@ class Restoring */ public function handle($model) { - if (! $model->isUserstamping()) { + if (! $model->isUserstamping() || is_null($model->getDeletedByColumn())) { return; } diff --git a/src/Listeners/Updating.php b/src/Listeners/Updating.php index bf75972..9f1188c 100644 --- a/src/Listeners/Updating.php +++ b/src/Listeners/Updating.php @@ -14,7 +14,7 @@ class Updating */ public function handle($model) { - if (! $model->isUserstamping() || is_null(Auth::id())) { + if (! $model->isUserstamping() || is_null($model->getUpdatedByColumn()) || is_null(Auth::id())) { return; } diff --git a/src/Userstamps.php b/src/Userstamps.php index 55a930a..bb4b47a 100644 --- a/src/Userstamps.php +++ b/src/Userstamps.php @@ -86,7 +86,7 @@ public function destroyer() */ public function getCreatedByColumn() { - return defined('static::CREATED_BY') && ! is_null(static::CREATED_BY) ? static::CREATED_BY : 'created_by'; + return defined('static::CREATED_BY') ? static::CREATED_BY : 'created_by'; } /** @@ -96,7 +96,7 @@ public function getCreatedByColumn() */ public function getUpdatedByColumn() { - return defined('static::UPDATED_BY') && ! is_null(static::UPDATED_BY) ? static::UPDATED_BY : 'updated_by'; + return defined('static::UPDATED_BY') ? static::UPDATED_BY : 'updated_by'; } /** @@ -106,7 +106,7 @@ public function getUpdatedByColumn() */ public function getDeletedByColumn() { - return defined('static::DELETED_BY') && ! is_null(static::DELETED_BY) ? static::DELETED_BY : 'deleted_by'; + return defined('static::DELETED_BY') ? static::DELETED_BY : 'deleted_by'; } /** diff --git a/tests/UserstampsTest.php b/tests/UserstampsTest.php index 1a26ed8..7df9902 100644 --- a/tests/UserstampsTest.php +++ b/tests/UserstampsTest.php @@ -230,14 +230,14 @@ public function testCustomColumnNamesAreSupported() $this->assertNull($foo->alt_deleted_by); } - public function testNullColumnNamesAreSupported() + public function testNullColumnNamesDisableUserstamps() { $this->app['auth']->loginUsingId(1); $foo = $this->createFooWithNullColumnNames(); - $this->assertEquals(1, $foo->created_by); - $this->assertEquals(1, $foo->updated_by); + $this->assertNull($foo->created_by); + $this->assertNull($foo->updated_by); $this->app['auth']->loginUsingId(2); @@ -245,11 +245,11 @@ public function testNullColumnNamesAreSupported() 'bar' => 'bar', ]); - $this->assertEquals(2, $foo->updated_by); + $this->assertNull($foo->updated_by); $foo->delete(); - $this->assertEquals(2, $foo->deleted_by); + $this->assertNull($foo->deleted_by); $foo->restore(); $this->assertNull($foo->deleted_by);