diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a1183a1..fca43a2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Cannot call method getKeyName\\(\\) on Illuminate\\\\Database\\\\Eloquent\\\\Model\\|null\\.$#" - count: 2 - path: src/Mixins/CollectionMixin.php - - - - message: "#^Cannot call method newModelQuery\\(\\) on Illuminate\\\\Database\\\\Eloquent\\\\Model\\|null\\.$#" - count: 1 - path: src/Mixins/CollectionMixin.php - - message: "#^PHPDoc tag @mixin contains generic class Illuminate\\\\Database\\\\Eloquent\\\\Collection but does not specify its types\\: TKey, TModel$#" count: 1 diff --git a/src/Mixins/CollectionMixin.php b/src/Mixins/CollectionMixin.php index ad39b0d..84c39ba 100644 --- a/src/Mixins/CollectionMixin.php +++ b/src/Mixins/CollectionMixin.php @@ -13,15 +13,16 @@ class CollectionMixin public function loadAttributes(): Closure { return function (Closure $closure): self { - if ($this->isEmpty()) { + $model = $this->first(); + if ($model === null) { return $this; } - $query = $this->first()->newModelQuery() + $query = $model->newModelQuery() ->whereKey($this->modelKeys()) - ->select($this->first()->getKeyName()); + ->select($model->getKeyName()); $query = $closure($query) ?? $query; - $models = $query->get()->keyBy($this->first()->getKeyName()); + $models = $query->get()->keyBy($model->getKeyName()); $attributes = Arr::except( array_keys($models->first()->getAttributes()),