diff --git a/src/Tools/Utils.php b/src/Tools/Utils.php index a951fb02..1113d9eb 100644 --- a/src/Tools/Utils.php +++ b/src/Tools/Utils.php @@ -197,7 +197,15 @@ public static function getModelFactory(string $modelName, array $states = [], ar $factory = $factory->$methodName(); } } else { - $factory = factory($modelName); + try { + $factory = factory($modelName); + } catch (\Throwable $e) { + if (Str::contains($e->getMessage(), "Call to undefined function Knuckles\Scribe\Tools\factory()")) { + throw new \Exception("Couldn't find the Eloquent model factory. Did you add the HasFactory trait to your $modelName model?"); + } else { + throw $e; + } + } if (count($states)) { $factory = $factory->states($states); }