Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a city inside a specific country with Faker

I'm working with the Faker extension in Laravel 5 to populate my database.

I have "countries" and "Cities" tables so I called

$faker->country

but how can I get a city that is inside that country?

I don't want "Bogotá" to belong to "EEUU".

like image 632
Sredny M Casanova Avatar asked Oct 30 '15 21:10

Sredny M Casanova


People also ask

Does faker JS still work?

The epic of one of the most beloved open source JS libraries took a quick turn to the dark side. On the 5th of January 2022, a new version of Faker was released by Marak, versioned intentionally 6.6. 6. This marked the unforeseen extinction of the library which was essentially completely deleted from NPM and Github.

What is faker JS for?

faker. js is a JavaScript library for generating fake data. Fake data is useful when building and testing our application. The faker. js can generate fake data for various areas, including address, commerce, company, date, finance, image, random, or name.


1 Answers

You'd make a generator and add only the provider for that country (a list of them can be found here):

$faker = new Faker\Generator();
$faker->addProvider(new Faker\Provider\en_AU\Address($faker));
$faker->state; // will give you only Australian states

If your specific need isn't covered by the available providers, you may need to create a custom provider.

like image 109
ceejayoz Avatar answered Sep 20 '22 11:09

ceejayoz