diff --git a/src/LoadActorVoteRelationship.php b/src/LoadActorVoteRelationship.php index 2543223..3ca41b4 100644 --- a/src/LoadActorVoteRelationship.php +++ b/src/LoadActorVoteRelationship.php @@ -40,12 +40,12 @@ public static function sumRelation($controller, $data): void } elseif ($data instanceof Collection) { $loadable = (new Post())->newCollection($data->map(function ($model) { return $model instanceof Discussion ? ($model->mostRelevantPost ?? $model->firstPost) : $model; - })); + })->filter()); } elseif ($data instanceof Post) { $loadable = $data->newCollection([$data]); } - if ($loadable) { + if ($loadable && $loadable instanceof Collection) { $loadable->loadSum('actualvotes', 'value'); } }