Skip to content

Commit 090cbe4

Browse files
authored
allow fakerphp/faker to not be installed (#56953)
1 parent ffc9dc0 commit 090cbe4

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
"ably/ably-php": "Required to use the Ably broadcast driver (^1.0).",
182182
"aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage, and SES mail driver (^3.322.9).",
183183
"brianium/paratest": "Required to run tests in parallel (^7.0|^8.0).",
184-
"fakerphp/faker": "Required to use the eloquent factory builder (^1.9.1).",
184+
"fakerphp/faker": "Required to generate fake data using the fake() helper (^1.9.1).",
185185
"filp/whoops": "Required for friendly error pages in development (^2.14.3).",
186186
"laravel/tinker": "Required to use the tinker console command (^2.0).",
187187
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^3.25.1).",

src/Illuminate/Database/DatabaseServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ protected function registerConnectionServices()
9696
*/
9797
protected function registerFakerGenerator()
9898
{
99+
if (! class_exists(FakerGenerator::class)) {
100+
return;
101+
}
102+
99103
$this->app->singleton(FakerGenerator::class, function ($app, $parameters) {
100104
$locale = $parameters['locale'] ?? $app['config']->get('app.faker_locale', 'en_US');
101105

src/Illuminate/Database/Eloquent/Factories/Factory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,14 @@ public static function dontExpandRelationshipsByDefault()
953953
/**
954954
* Get a new Faker instance.
955955
*
956-
* @return \Faker\Generator
956+
* @return \Faker\Generator|null
957957
*/
958958
protected function withFaker()
959959
{
960+
if (! class_exists(Generator::class)) {
961+
return;
962+
}
963+
960964
return Container::getInstance()->make(Generator::class);
961965
}
962966

0 commit comments

Comments
 (0)