I'm creating seeders for my models and I chose to use factories to be able to add several records without much effort.
But I found a problem! It seems that the Factory class expects my project's architecture to be App/Models and so all my tables are there, but the project I'm currently working on is all structured differently... The models are each in one place separate. I would have to find a more dynamic way to make Factory access each model... Does anyone have any idea what to do?
Ex.: a model is in App/Modules/Contents/Models
Below is the Factory class method that returns the model path:
public function modelName()
{
$resolver = static::$modelNameResolver ?: function (self $factory) {
$namespacedFactoryBasename = Str::replaceLast(
'Factory', '', Str::replaceFirst(static::$namespace, '', get_class($factory))
);
$factoryBasename = Str::replaceLast('Factory', '', class_basename($factory));
$appNamespace = static::appNamespace();
return class_exists($appNamespace.'Models\'.$namespacedFactoryBasename)
? $appNamespace.'Models\'.$namespacedFactoryBasename
: $appNamespace.$factoryBasename;
};
return $this->model ?: $resolver($this);
}