Skip to content

Commit 2228233

Browse files
committed
cache created faker instances
1 parent 7ed9e2e commit 2228233

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Illuminate/Database/DatabaseServiceProvider.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
class DatabaseServiceProvider extends ServiceProvider
1515
{
16+
/**
17+
* The array of resolved Faker instances.
18+
*
19+
* @var array
20+
*/
21+
protected static $fakers = [];
22+
1623
/**
1724
* Bootstrap the application events.
1825
*
@@ -75,7 +82,13 @@ protected function registerConnectionServices()
7582
protected function registerEloquentFactory()
7683
{
7784
$this->app->singleton(FakerGenerator::class, function ($app, $parameters) {
78-
return FakerFactory::create($parameters['locale'] ?? $app['config']->get('app.faker_locale', 'en_US'));
85+
$locale = $parameters['locale'] ?? $app['config']->get('app.faker_locale', 'en_US');
86+
87+
if (! isset(static::$fakers[$locale])) {
88+
static::$fakers[$locale] = FakerFactory::create($locale);;
89+
}
90+
91+
return static::$fakers[$locale];
7992
});
8093

8194
$this->app->singleton(EloquentFactory::class, function ($app) {

0 commit comments

Comments
 (0)