diff --git a/framework/core/src/Database/Eloquent/Collection.php b/framework/core/src/Database/Eloquent/Collection.php index ef5c5fe87d..a9eda56003 100644 --- a/framework/core/src/Database/Eloquent/Collection.php +++ b/framework/core/src/Database/Eloquent/Collection.php @@ -72,13 +72,14 @@ protected function loadMissingRelation(BaseCollection $models, array $path): voi $relation = reset($relation); } + // @phpstan-ignore-next-line $models->filter(fn ($model) => ! is_null($model) && ! $model->relationLoaded($name))->load($relation); if (empty($path)) { return; } - $models = $models->pluck($name)->where(fn (mixed $relation) => $relation !== null); + $models = $models->pluck($name)->filter(); if ($models->first() instanceof \Illuminate\Support\Collection) { $models = $models->collapse();