Skip to content

Commit

Permalink
Merge pull request #75 from sald19/main
Browse files Browse the repository at this point in the history
Fix lazy load on model causer when shouldBeStrict is enabled
  • Loading branch information
noxoua authored Jul 12, 2024
2 parents 003e20d + dde92b4 commit 060fe4e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Loggers/Loggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Noxo\FilamentActivityLog\Loggers;

use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Filesystem\Filesystem;
use ReflectionClass;

Expand All @@ -15,7 +16,9 @@ class Loggers
public static function getLoggerByModel(string $model, bool $force = false): ?string
{
foreach (self::$loggers as $logger) {
if ($logger::$model === $model && (! $logger::$disabled || $force)) {
$alias = Relation::getMorphAlias($logger::$model) ?? $logger::$model;

if ($alias === $model && (! $logger::$disabled || $force)) {
return $logger;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Pages/Concerns/HasListFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -170,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',
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/ListActivities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}

Expand Down

0 comments on commit 060fe4e

Please sign in to comment.