Skip to content

Commit

Permalink
Throw error if factory instantiation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Jun 24, 2021
1 parent d79be99 commit 5eb0d72
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Tools/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5eb0d72

Please sign in to comment.