From 67f186749a4d9ff18e0d26f77ab6ed2bdde0fb36 Mon Sep 17 00:00:00 2001 From: Dominik Kohler <18621527+kohlerdominik@users.noreply.github.com> Date: Mon, 7 Feb 2022 19:13:45 +0100 Subject: [PATCH] Fixed Undefined Key error in nested relationship --- src/BaseRelation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaseRelation.php b/src/BaseRelation.php index 3b3b592..6d8cdb9 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -158,7 +158,7 @@ public function addEagerConstraints(array $models) // The first model in the array is always the parent, so add the scope constraints based on that model. // @link https://github.com/laravel/framework/pull/25240 // @link https://github.com/lazychaser/laravel-nestedset/issues/351 - optional($models[0])->applyNestedSetScope($this->query); + optional(reset($models))->applyNestedSetScope($this->query); $this->query->whereNested(function (Builder $inner) use ($models) { // We will use this query in order to apply constraints to the