fix(filament): fixed pivot action logs (#939)

This commit is contained in:
Kyrch
2025-08-27 22:28:43 -03:00
committed by GitHub
parent 7cdf7c90dc
commit 7e2712386d
2 changed files with 5 additions and 5 deletions
@@ -25,10 +25,9 @@ trait HasPivotActionLogs
if ($relation instanceof BelongsToMany) {
$pivotClass = $relation->getPivotClass();
// TODO: This needs to be updated/fixed for member/group artist relation
$pivot = $pivotClass::query()
->where($ownerRecord->getKeyName(), $ownerRecord->getKey())
->where($record->getKeyName(), $record->getKey())
->where($relation->getForeignPivotKeyName(), $ownerRecord->getKey())
->where($relation->getRelatedPivotKeyName(), $record->getKey())
->first();
ActionLog::modelPivot(
@@ -36,7 +35,7 @@ trait HasPivotActionLogs
$ownerRecord,
$record,
$pivot ?? $record,
$action
$action,
);
}
}
+2 -1
View File
@@ -15,6 +15,7 @@ use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
@@ -302,7 +303,7 @@ class ActionLog extends Model implements Nameable
ActionLog::ATTRIBUTE_TARGET_TYPE => Relation::getMorphAlias($parent->getMorphClass()),
ActionLog::ATTRIBUTE_TARGET_ID => $parent->getKey(),
ActionLog::ATTRIBUTE_MODEL_TYPE => Relation::getMorphAlias($pivot->getMorphClass()),
ActionLog::ATTRIBUTE_MODEL_ID => $pivot->getKey(),
ActionLog::ATTRIBUTE_MODEL_ID => $pivot instanceof Pivot ? null : $pivot->getKey(),
ActionLog::ATTRIBUTE_FIELDS => $data ? static::getFields($data) : static::getFields($pivot->getAttributes(), $pivot),
ActionLog::ATTRIBUTE_STATUS => ActionLogStatus::FINISHED->value,
ActionLog::ATTRIBUTE_FINISHED_AT => Date::now(),