From b6d8b272912e26e5e00bd978e6577ee6e2da465a Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Fri, 26 Jul 2024 21:07:15 +0300 Subject: [PATCH] do not attempt instantiating non-instantiable models (#469) --- src/Support/ResponseExtractor/ModelInfo.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 59d10166..e34fa0ef 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -53,6 +53,16 @@ public function handle() { $class = $this->qualifyModel($this->class); + $reflectionClass = new ReflectionClass($class); + if (! $reflectionClass->isInstantiable()) { + return collect([ + 'instance' => null, + 'class' => $class, + 'attributes' => collect(), + 'relations' => collect(), + ]); + } + /** @var Model $model */ $model = app()->make($class); @@ -71,6 +81,9 @@ public function type() } $modelInfo = $this->handle(); + if (! $modelInfo->get('instance')) { + return new ClassDefinition($modelInfo->get('class')); + } /** @var Model $model */ $model = app()->make($modelInfo->get('class'));