Skip to content

Commit

Permalink
fix: use getNumericMorphMap to resolve the numeric morph
Browse files Browse the repository at this point in the history
  • Loading branch information
rbondoc96 committed Nov 20, 2024
1 parent 294cb39 commit 9fbc05a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Commands/AuditModelResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sourcetoad\Logger\Commands;

use Illuminate\Console\Command;
use Sourcetoad\Logger\Logger;
use Sourcetoad\Logger\Helpers\AuditResolver;
use Sourcetoad\Logger\Models\AuditChange;
use Sourcetoad\Logger\Models\AuditModel;
Expand All @@ -21,7 +22,7 @@ public function handle(): void

$item->processed = true;
$item->owner_id = $owner?->getKey();
$item->owner_type = $owner?->getMorphClass();
$item->owner_type = !is_null($owner) ? Logger::getNumericMorphMap($owner) : null;
$item->saveOrFail();
}
});
Expand All @@ -33,7 +34,7 @@ public function handle(): void

$item->processed = true;
$item->owner_id = $owner?->getKey();
$item->owner_type = $owner?->getMorphClass();
$item->owner_type = !is_null($owner) ? Logger::getNumericMorphMap($owner) : null;
$item->saveOrFail();
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function logActivity(int $type, array $keys = []): AuditActivity

$data[] = [
'activity_id' => $activity->id,
'entity_type' => $this->getNumericMorphMap($model),
'entity_type' => static::getNumericMorphMap($model),
'entity_id' => $model->getKey(),
'key_id' => $keys->id,
'processed' => false,
Expand Down Expand Up @@ -156,7 +156,7 @@ public function logActivity(int $type, array $keys = []): AuditActivity

$data[] = [
'activity_id' => $activity->id,
'entity_type' => $this->getNumericMorphMap($model),
'entity_type' => static::getNumericMorphMap($model),
'entity_id' => $model->getKey(),
'processed' => false,
];
Expand All @@ -171,7 +171,7 @@ public function logActivity(int $type, array $keys = []): AuditActivity
// Private functions
//--------------------------------------------------------------------------------------------------------------

private function getNumericMorphMap(Model $model): int
public static function getNumericMorphMap(Model $model): int
{
$fcqn = get_class($model);
$morphMap = LoggerServiceProvider::$morphs;
Expand Down

0 comments on commit 9fbc05a

Please sign in to comment.