Generate Dummy Data with Faker in Laravel
Starting from Laravel 5, Faker is included by default in the framework. The Faker library is a great tool for generating dummy data. It’s been around for quite a while and is used by a lot of developers. One of the benefits of using the Faker library is that you can generate realistic data. This can be helpful for testing purposes or when you need to populate a database with data.
In this tutorial, we’ll show you how to use the Faker library to generate dummy data in a Laravel application.
use Faker\Factory as Faker; $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(), ]);
//it can be used in route Route::get('/dummy',function(){ $faker = Faker::create(); echo 'Random Address: ' . $faker->unique()->email; });