小峰的博客
参考文档: https://github.com/fzaninotto/Faker
在 database\factories\ModelFactory.php 文件,添加给posts表填充数据规则
database\factories\ModelFactory.php
1234567891011121314151617
$factory->define(App\Post::class, function (Faker\Generator $faker) { return [ 'title' => $faker->sentence(6),// 最多6个单词 'content' => $faker->paragraph(10),// 10条语句 ];});``` ## 填充10条数据并打印出来在命令行使用tinker```bash$ php artisan tinkerPsy Shell v0.9.12 (PHP 7.2.1 — cli) by Justin Hileman>>> factory(App\Post::class, 10)->make();
在命令行使用tinker
1234
$ php artisan tinkerPsy Shell v0.9.12 (PHP 7.2.1 — cli) by Justin Hileman>>> factory(App\Post::class, 10)->create();