Using php artisan make:seeder
=========================
php artisan make:seeder PeopleTableSeeder
inside PeopleTableSeeder class
In DatabaseSeeder class
For multiple entry
======================
Using PHP factory
====================
=========================
php artisan make:seeder PeopleTableSeeder
inside PeopleTableSeeder class
<?php
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
use Carbon\Carbon;
class PeopleTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker::create();
DB::table('people')->insert(
[
'first_name' => $faker->firstname,
'last_name' => $faker->lastname,
'age' => rand(10, 44),
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
]
);
}
}
In DatabaseSeeder class
$this->call(PeopleTableSeeder::class);
For multiple entry
======================
DB::table('people')->insert([
[], []
]);
====================
$factory->define(App\Person::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'first_name' => $faker->firstname,
'last_name' => $faker->lastname,
'age' => rand(10, 44)
];
});
In DatabaseSeeder classfactory(Person::class, 100000)->create();