laravel的工厂模式数据填充:

数据表post中的字段结构。

 

database\factory\UserFactory.php

$factory->define(App\Post::class,function (Faker $faker){
    return [
      'title'=>$faker->sentence(6), //sentence:句子(填充句子) 
    'content'=>$faker->paragraph(10) //paragraph:段落;短评 (填充段落)
];
});

 

在命令行窗口调用tinker方法,去执行数据填充命令:

php artisan tinker

factory(App\Post:class,20)->create(); //往数据库中的Post数据表中填充20条数据:

 

相关文章:

  • 2021-08-21
  • 2022-01-24
  • 2021-06-19
  • 2022-12-23
  • 2018-10-20
  • 2021-05-23
  • 2022-12-23
  • 2021-10-07
猜你喜欢
  • 2022-01-18
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
相关资源
相似解决方案