Faker get matching country and code from locale I'm trying to create random language with real country/code/etc but everything in faker is random even with locale set.
$locale = config('app.faker_locale');
$faker = fake($locale);
$name = $faker->country;
$code = $faker->countryCode;
$iso = $faker->countryISOAlpha3;
Country::create([
'name' => $name,
'locale' => $locale,
'iso' => $iso,
'code' => $code,
]);
Is there a way of getting the whole country details?
You can use the Faker\Provider\Base class to get the country details you need. The country method will return an array with the country name, code, and ISO Alpha 3 code.
$locale = config('app.faker_locale');
$faker = Faker\Factory::create($locale);
$country = $faker->country;
Language::create([
'name' => $country['name'],
'locale' => $locale,
'iso' => $country['iso_alpha3'],
'code' => $country['country_code'],
]);
This is returning the country name only
$country = $faker->country;
Please sign in or create an account to participate in this conversation.