Usage
Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
This Faker package has been made to answer all previous Faker conception problems.
- Huge download size (More than 3MB)
- Not handling extension well (for open source packages)
- Can't use multiple generators (unique / regex)
- Architecture caveats
Installation
Faker requires PHP >= 8.3.
composer require --dev xefi/faker-php
Basic usage
Using the faker instance you are able to call any extension methods directly.
$faker = new Xefi\Faker\Faker;
echo $faker->numberBetween(1, 10);
You might call the same instance multiple times for different results
for ($i = 0; $i < 3; $i++) {
echo $faker->numberBetween(1, 10);
}
// 4
// 7
// 3
Localization
By default, the locale is set to en_US
. If you want to customize yours, see: https://github.com/TiagoDanin/Locale-Codes
Be aware that by default you also have extensions with no locales for your comfort. For example, by using the default package you have a colors extension with latin name.
You have two way to change the faker locale:
Globally
use Xefi\Faker\Faker;
$faker = new Faker('fr_FR');
$faker->name() // Marie Durand
$faker->name() // Pierre Dupont
For a single execution
use Xefi\Faker\Faker;
$faker = new Faker();
$faker->locale('fr_FR')->name() // Marie Durand
$faker->name() // John Doe (no locale)