Laravel用seed简单填充数据
in 交流 with 2 comments

Laravel用seed简单填充数据

in 交流 with 2 comments

因为需要测试,看了下文档,不用factory模式进行数据生成

第一步:
php artisan make:seed TestData

然后在database下的seeds目录下找到DatabaseSeed文件和testdata文件修改RUN方法
//==DatabaseSeed的run

$this->call(KehuTest::class);

//==testdata 的run

for ($i=0;$i<1000;$i++){ $faker = \Faker\Factory::create('zh_CN');
DB::table('crm_self_kehuxinxi')->insert([
['KeHuXinXi_KeHuMingChen' => $faker->name, 'KeHuXinXi_KeHuXingBie' => '男', 'KeHuXinXi_KeHuDianHua' => $faker->phoneNumber,
'KeHuXinXi_KeHuDiZhi'=>$faker->address, 'KeHuXinXi_WeiXin'=>$faker->phoneNumber,
'KeHuXinXi_BeiZhu'=>$faker->citySuffix, 'KeHuXinXi_KeHuShengRi'=>$faker->dateTime,
'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s")],
]);
}

第二步:

$this->call(TestData::class);

第三步:

composer dump-autoload

第四步:
php artisan db:seed

留言
  1. 我是作者 色

    6666

    Reply
  2. 过来转转
    虽然看不懂ToT

    Reply