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".
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".
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.
In Laravel factory,This should do the trick.
use Faker\Provider\en_AU\Address;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'country' => $this->faker->country(),
'city' => $this->faker->city(),
'state' => Address::state(),
];
}