php-fakerHow do I generate a list of fake data using Laravel Faker?
Using the Laravel Faker library, you can generate a list of fake data. Here is an example code block to generate a list of 10 fake names:
<?php
use Faker\Factory as Faker;
$faker = Faker::create();
for ($i = 0; $i < 10; $i++) {
echo $faker->name . "\n";
}
The output of this code block will be a list of 10 fake names, such as:
John Smith
Anna Jones
Sarah Brown
Mark Wilson
Steven Johnson
Karen Williams
Daniel Miller
Elizabeth Davis
Brian Anderson
David Taylor
The code block consists of the following parts:
use Faker\Factory as Faker;
: This line imports the Faker library.$faker = Faker::create();
: This line creates an instance of the Faker class.for ($i = 0; $i < 10; $i++)
: This is a for loop that will execute 10 times.echo $faker->name . "\n";
: This line prints out a fake name and adds a new line character.
You can use the Faker library to generate a variety of fake data, such as addresses, phone numbers, emails, etc. You can find the full list of available options in the Faker documentation.
More of Php Faker
- How do I generate a zip file using PHP Faker?
- How do I generate a random digit using PHP Faker?
- How do I generate a fake year in Laravel using Faker?
- How do I use PHP Faker to generate XML data?
- How do I check which version of Laravel Faker I am using?
- How can I specify the word length when using Laravel Faker?
- How do I generate a valid VAT number using Laravel Faker?
- How do I generate fake state data using PHP Faker?
- How can I generate a random string using PHP Faker?
- How can I generate a zip code using Laravel Faker?
See more codes...