From 53c8c3fc0af9eee4686849d930eef7a93ec63617 Mon Sep 17 00:00:00 2001 From: Nobel Dahal Date: Wed, 7 Feb 2024 19:07:17 +0545 Subject: [PATCH] Fix - `getRelated()` on null for relationship discovery (#790) Addresses an issue by introducing an additional instanceof check for the `$relation` to see if it's a valid relationship. If not, bail early. --- src/Drivers/EloquentEntitySet.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Drivers/EloquentEntitySet.php b/src/Drivers/EloquentEntitySet.php index 6fc4e5f53..fe1739a5b 100644 --- a/src/Drivers/EloquentEntitySet.php +++ b/src/Drivers/EloquentEntitySet.php @@ -514,6 +514,13 @@ public function discoverRelationship( /** @var Relation $relation */ $relation = $model->$method(); + if (!$relation instanceof Relation) { + throw new ConfigurationException( + 'invalid_relationship', + 'The method could not return a valid relationship' + ); + } + $relatedModel = get_class($relation->getRelated()); $right = Lodata::getResources()->sliceByClass(self::class)->find(function ($set) use ($relatedModel) {