Getting Started
Strategies
Strategies allows to play with faker during random data generation
Strategies are a way to control the data you are generating, you are free to add as many as you want
Unique
Make sure the data you generate is not duplicated with this strategy
use Xefi\Faker\Faker;
$faker = new Faker();
$faker->unique()->numberBetween(1, 2); // 1
$faker->unique()->numberBetween(1, 2); // 2
$faker->unique()->numberBetween(1, 2); // Error too many tries
The unique strategy also gives the possibility to use a seed to have multiple unique generator:
use Xefi\Faker\Faker;
$faker = new Faker();
$faker->unique('my-seed')->numberBetween(1, 2); // 1
$faker->unique('my-seed')->numberBetween(1, 2); // 2
$faker->unique('my-other-seed')->numberBetween(1, 2); // 1
Regex
Regex strategy gives you the possibility to validate your data with a given regex expression:
use Xefi\Faker\Faker;
$faker = new Faker();
$faker->regex('/^01$/')->postalCode(); // Postal code that begins with '01'
$faker->regex('/.com$/')->email(); // Email that ends with '.com'