Just for the record I've been trying to bind the creation of the Illuminate\Database\Eloquent\Factory in an service provider as below:
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\ServiceProvider;
class FactoryServiceProvider extends ServiceProvider
{
public function register()
{
$this->registerFactory();
}
public function registerFactory()
{
$this->app->bind(Factory::class, function () {
return Factory::construct(env('FACTORIES_PATH', '../database/factories'));
});
}
}
But that doesn't works