laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Ability to configure faker via DI container. #2026

Open Legion112 opened 4 years ago

Legion112 commented 4 years ago

Here code of a trade that create a faker.

    /**
     * Create a Faker instance for the given locale.
     *
     * @param  string|null  $locale
     * @return \Faker\Generator
     */
    protected function makeFaker($locale = null)
    {
        return Factory::create($locale ?? config('app.faker_locale', Factory::DEFAULT_LOCALE));
    }

https://github.com/laravel/framework/blob/afcfcf27299f1cd3a5146ab6930f363bee453156/src/Illuminate/Foundation/Testing/WithFaker.php#L45

There is no ability to configure creating of Faker via DI container. It would be more flexible if we use app()->make(\Faker\Generator::class)

joelharkes commented 4 years ago

Agree, we just overwriten this function To do this and add the subclass to container ;-)