<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateDatabaseEloquentFactoriesFactory;
use IlluminateSupportStr;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
//Add THIS
Factory::guessFactoryNamesUsing(function (string $model_name) {
$namespace = 'DatabaseFactories';
$model_name = Str::afterLast($model_name, '');
return $namespace . $model_name . 'Factory';
});
}
}
// If you factory is out of standard, you can set an specifc
// On your model, create a static method named newFactory
protected static function newFactory()
{
return DatabaseFactoriesMyModelFactory::new();
}
//On your factory, add this
protected $model = AppModelsMyModel::class;