Skip to content

Commit

Permalink
* Blueprint is now macroed instead of extended.
Browse files Browse the repository at this point in the history
* Removed events registered control from the trait.
  • Loading branch information
jlorente committed Aug 15, 2019
1 parent 160e265 commit 055d2cd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 55 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jlorente",
"laravel",
"identity",
"auditable",
"identitystamp",
"created_by",
"updated_by",
Expand Down
18 changes: 4 additions & 14 deletions src/Database/Eloquent/IdentityStamps.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,12 @@
trait IdentityStamps
{

/**
* Variable to control the event loaded method.
*
* @var bool
*/
protected static $identityStampsEventsLoaded = false;

/**
* Method to boot the trait behaviors.
*/
public static function bootIdentityStamps()
{
if (static::$identityStampsEventsLoaded === false) {
static::attachIdentityStampsEvents();
static::$identityStampsEventsLoaded = true;
}
static::attachIdentityStampsEvents();
}

/**
Expand All @@ -47,7 +37,7 @@ protected static function attachIdentityStampsEvents()

if (array_search(SoftDeletes::class, class_uses_recursive(static::class)) !== false) {
static::deleted(function($model) {
$model->updateSoftDeletesIdentityStamps();
$model->touchSoftDeletesIdentityStamps();
});
}
}
Expand Down Expand Up @@ -104,7 +94,7 @@ protected function updateSoftDeletesIdentityStamps()

$identity = $this->getIdentityStampValue();

$deletedBy = $this->getUpdatedByColumn();
$deletedBy = $this->getDeletedByColumn();
$this->{$deletedBy} = $identity;
}

Expand All @@ -121,7 +111,7 @@ protected function touchSoftDeletesIdentityStamps()

$this->updateSoftDeletesIdentityStamps();

$deletedBy = $this->getCreatedByColumn();
$deletedBy = $this->getDeletedByColumn();

$this->update([
$deletedBy => $this->{$deletedBy}
Expand Down
37 changes: 0 additions & 37 deletions src/Database/Schema/Blueprint.php

This file was deleted.

12 changes: 8 additions & 4 deletions src/IdentityStampServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

namespace Jlorente\Laravel\IdentityStamp;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\DB;
use Jlorente\Laravel\IdentityStamp\Database\Schema\Blueprint;

/**
* Class IdentityStampServiceProvider.
Expand All @@ -39,8 +38,13 @@ class IdentityStampServiceProvider extends ServiceProvider
*/
public function register()
{
DB::getSchemaBuilder()->blueprintResolver(function($table, $callback) {
return new Blueprint($table, $callback);
Blueprint::macro('identityStamps', function() {
$this->unsignedInteger('created_by')->nullable();
$this->unsignedInteger('updated_by')->nullable();
});

Blueprint::macro('softDeletesIdentityStamps', function() {
$this->unsignedInteger('deleted_by')->nullable();
});
}

Expand Down

0 comments on commit 055d2cd

Please sign in to comment.