需要在composer.json 里添加
"require": {
"laravel/framework": "4.2.*",
"nesbot/carbon": "^1.22",
"fzaninotto/faker": "1.4.*"
},
1、创建PersonTableSeeder
<?php
use Faker\Factory as Faker;
class PersonTableSeeder extends Seeder {
public function run()
{
$faker = Faker::create();
// DB::table('person')->delete();
foreach (range(1, 50) as $index) {
$res =Person::create([
'id' => $index,
'person_id_mdm'=>str_random(6),
'update_time'=> \Carbon\Carbon::now(),
'avatar'=>'',
]);
}
}
}
2、在DatabaseSeeder.php中
<?php
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
$this->call('PersonTableSeeder');
}
}
3、执行php artisan db:seed