Skip to content

Commit

Permalink
fix: handle situations where model has no factories
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Apr 29, 2022
1 parent 1809e8e commit 0e1ade2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Traits/FactoryLocatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait FactoryLocatorTrait
{
protected static function newFactory(): Factory
protected static function newFactory(): ?Factory
{
$separator = '\\';
$containersFactoriesPath = $separator . 'Data' . $separator . 'Factories' . $separator;
Expand All @@ -17,6 +17,11 @@ protected static function newFactory(): Factory

Factory::useNamespace($nameSpace);
$className = class_basename(static::class);

if (!class_exists($className)) {
return null;
}

return Factory::factoryForModel($className);
}
}

0 comments on commit 0e1ade2

Please sign in to comment.