diff --git a/src/Jenssegers/Mongodb/Eloquent/Model.php b/src/Jenssegers/Mongodb/Eloquent/Model.php index ce4003dec..295114ea1 100644 --- a/src/Jenssegers/Mongodb/Eloquent/Model.php +++ b/src/Jenssegers/Mongodb/Eloquent/Model.php @@ -239,11 +239,7 @@ protected function getAttributeFromArray($key) { // Support keys in dot notation. if (str_contains($key, '.')) { - $attributes = array_dot($this->attributes); - - if (array_key_exists($key, $attributes)) { - return $attributes[$key]; - } + return array_get($this->attributes, $key); } return parent::getAttributeFromArray($key); diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 4058f1382..5837229a5 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -495,6 +495,22 @@ public function testDotNotation() $this->assertEquals('Strasbourg', $user['address.city']); } + public function testMultipleLevelDotNotation() + { + $book = Book::create([ + 'title' => 'A Game of Thrones', + 'chapters' => [ + 'one' => [ + 'title' => 'The first chapter', + ], + ], + ]); + + $this->assertEquals(['one' => ['title' => 'The first chapter']], $book->chapters); + $this->assertEquals(['title' => 'The first chapter'], $book['chapters.one']); + $this->assertEquals('The first chapter', $book['chapters.one.title']); + } + public function testGetDirtyDates() { $user = new User();