Faker provider to generate random valid Swiss locations.
You can install the package via composer:
composer require wnx/faker-swiss-locations
You first need to add the Location
provider to Faker.
// Add Location Provider to Faker
$faker = Factory::create();
$faker->addProvider(new Wnx\FakerSwissLocations\Provider\Location($faker));
You can now call the postcode()
, city()
or canton()
method on faker to get a random valid Swiss location.
Note Calling
postcode()
,city()
orcanton()
always returns a new random location. If you need the same location forpostcode
,city
andcanton
use thelocation()
-method and access the properties from the instance.
// 8000
$faker->postcode();
// Zürich
$faker->city();
// Instance of Wnx\SwissCantons\Canton
$faker->canton();
$faker->canton()->getName(); // Zürich
$faker->canton()->getAbbreviation(); // ZH
Or you can call the location()
method to get a \Wnx\FakerSwissLocations\Location
-instance. You can access postcode, city and canton from this object too.
// Instance of \Wnx\FakerSwissLocations\Location
$location = $faker->location();
$location->postcode; // 8000
$location->city; // Zürich
$location->canton; // Instance of Wnx\SwissCantons\Canton
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.