When it comes to generating dummy data for PHP application, Faker is the most well-known library. It can be used to generate any types of data, from a number, human’s name, city, to credit card number, username, password.
I wrote a post about using Faker in CodeIgniter. There are some steps to follow to use Faker. However, we don’t need those steps applied to Laravel, the framework (v5.0+) already has Faker built-in.
To test some functions of the Faker library you just need to create a Faker object and return data from some methods from your web routes file .
Add library
use Faker\Factory as Faker;
Test function in web route
Route::get('/dummy',function(){ $faker = Faker::create(); echo 'Email Address: ' . $faker->unique()->email; });
Insert data
$faker = Faker::create(); DB::table('account')->insert([ 'username' => $faker->userName(), 'password' => $faker->password(), 'about' => $faker->sentence(), 'created_at' => \Carbon\Carbon::now(), 'Updated_at' => \Carbon\Carbon::now(), ]);