From 0052ba56ecc1447c86f14136fc1ce47d4dbd4f7d Mon Sep 17 00:00:00 2001 From: sald19 Date: Thu, 16 May 2024 10:52:22 -0600 Subject: [PATCH 1/4] fix lazy load on model causer when shouldBeStrict is enabled --- src/Pages/ListActivities.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pages/ListActivities.php b/src/Pages/ListActivities.php index d550fc9..25e7d78 100644 --- a/src/Pages/ListActivities.php +++ b/src/Pages/ListActivities.php @@ -63,7 +63,7 @@ public function getActivities() $activityModel = config('activitylog.activity_model') ?? Activity::class; return $this->paginateTableQuery( - $this->applyFilters($activityModel::latest()) + $this->applyFilters($activityModel::with('causer')->latest()) ); } From c91463b64b54f2120bc8dac0d3071c1704b60e5e Mon Sep 17 00:00:00 2001 From: sald19 Date: Sat, 25 May 2024 10:04:16 -0600 Subject: [PATCH 2/4] load causer for causer function field en query --- src/Pages/Concerns/HasListFilters.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Pages/Concerns/HasListFilters.php b/src/Pages/Concerns/HasListFilters.php index a8ff8c2..6a3177b 100644 --- a/src/Pages/Concerns/HasListFilters.php +++ b/src/Pages/Concerns/HasListFilters.php @@ -142,6 +142,7 @@ protected function getCauserField() ->allowHtml() ->options(function () { $causers = Activity::query() + ->with('causer') ->groupBy('causer_id', 'causer_type') ->get(['causer_id', 'causer_type']) ->filter(fn ($activity) => $activity->causer instanceof Eloquent\Model) From 44fc74ebfb253c4fcad31b8d5942413b55f95b6a Mon Sep 17 00:00:00 2001 From: sald19 Date: Tue, 9 Jul 2024 21:29:02 -0600 Subject: [PATCH 3/4] use morphMap method for get class moph --- src/Loggers/Loggers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Loggers/Loggers.php b/src/Loggers/Loggers.php index 30b7b95..91d4496 100644 --- a/src/Loggers/Loggers.php +++ b/src/Loggers/Loggers.php @@ -15,7 +15,7 @@ class Loggers public static function getLoggerByModel(string $model, bool $force = false): ?string { foreach (self::$loggers as $logger) { - if ($logger::$model === $model && (! $logger::$disabled || $force)) { + if (app($logger::$model)->getMorphClass() === $model && (! $logger::$disabled || $force)) { return $logger; } } From a36dfce8cc2e13e8cb343f1a16a380ee55d09865 Mon Sep 17 00:00:00 2001 From: sald19 Date: Wed, 10 Jul 2024 10:09:25 -0600 Subject: [PATCH 4/4] identify model by alias when has morphmap --- src/Loggers/Loggers.php | 5 ++++- src/Pages/Concerns/HasListFilters.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Loggers/Loggers.php b/src/Loggers/Loggers.php index 91d4496..94385bb 100644 --- a/src/Loggers/Loggers.php +++ b/src/Loggers/Loggers.php @@ -2,6 +2,7 @@ namespace Noxo\FilamentActivityLog\Loggers; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Filesystem\Filesystem; use ReflectionClass; @@ -15,7 +16,9 @@ class Loggers public static function getLoggerByModel(string $model, bool $force = false): ?string { foreach (self::$loggers as $logger) { - if (app($logger::$model)->getMorphClass() === $model && (! $logger::$disabled || $force)) { + $alias = Relation::getMorphAlias($logger::$model) ?? $logger::$model; + + if ($alias === $model && (! $logger::$disabled || $force)) { return $logger; } } diff --git a/src/Pages/Concerns/HasListFilters.php b/src/Pages/Concerns/HasListFilters.php index 6a3177b..14973e5 100644 --- a/src/Pages/Concerns/HasListFilters.php +++ b/src/Pages/Concerns/HasListFilters.php @@ -171,7 +171,7 @@ protected function getSubjectTypeField() ->options( array_column( array_map(fn ($logger) => [ - 'value' => $logger::$model, + 'value' => Eloquent\Relations\Relation::getMorphAlias($logger::$model) ?? $logger::$model, 'label' => $logger::getLabel(), ], Loggers::$loggers), 'label',