Hello everyone,
I'm pretty sure I'm being dumb here but I'm having issues with Faker locale.
In my config/app.php:
'locale' => 'en',
'faker_locale' => 'en_GB',
this works fine in a factory:
use Faker\Generator as Faker;
$factory->define(\App\Address::class, function (Faker $faker) {
return [
'country' => $faker->randomElement(['England','Wales','Scotland','Northern Ireland','Southern Ireland','United Kingdom']),
'country_code' => 'GB',
'town' => $faker->boolean(50) ? $faker->city() : null,
'county' => $faker->boolean(50) ? $faker->county() : null,
'address1' => $faker->boolean(50) ? $faker->buildingNumber() . ' ' . $faker->streetName() : null,
'address2' => $faker->boolean(80) ? $faker->streetName() : null,
'postcode' => $faker->boolean(50) ? $faker->postcode() : substr($faker->postcode(),0,3),
'is_verified' => $faker->boolean(50),
'is_live' => $faker->boolean(50),
'is_visible' => $faker->boolean(50),
'is_primary' => $faker->boolean(50),
'raw' => str_replace("\n",'<br>',$faker->address()),
'latitude' => $faker->latitude(49.82,59.47),
'longitude' => $faker->longitude(-10.85,2.02),
'profile_id' => 1,
];
});
but when I try in a test:
use Faker\Factory as Faker;
//
$faker = Faker::create();
$addressDetails = [
'country' => $faker->randomElement(['England', 'Wales', 'Scotland', 'Northern Ireland', 'Southern Ireland', 'United Kingdom']),
'country_code' => 'GB',
'town' => $faker->city(),
'county' => $faker->county(),
'address1' => $faker->buildingNumber() . ' ' . $faker->streetName(),
'address2' => $faker->streetName(),
'postcode' => $faker->postcode(),
'is_verified' => $faker->boolean(50),
'is_live' => $faker->boolean(50),
'is_visible' => $faker->boolean(50),
'is_primary' => true,
'latitude' => $faker->latitude(49.82,59.47),
'longitude' => $faker->longitude(-10.85,2.02),
];
then I get the error:
InvalidArgumentException: Unknown formatter "county"
and with
$faker = Faker::create('en_GB');
it works again fine!
I'm guessing it's to do with how I'm creating my instance of Faker that's causing the issue as it's not coming from the service container.
Thanks for any help.