当前位置:网站首页>laravel8使用faker调用工厂填充数据
laravel8使用faker调用工厂填充数据
2022-06-24 13:04:00 【s_罐装冰块】
1.通过命令安装填充文件。
php artisan make:seeder UserSeeder2.在database找到我们的填充文件

3.在我们的填充文件中写入功能方法
//编写种子文件(使用中文包)
$faker = Factory::create('zh_CN');
//根据我们的需要来填充多少测试数据(我这里是20所以就是填充20条数据)
for ($i = 0; $i <= 20; $i++) {
//调用模型进行填充数据
UddModel::create([
'username' => $faker->name,
'password' => bcrypt('123456'),]);
// 注:在我们填充数据的过程中加入创建时间字段(updated_at)和修改时间字段(updated_at)防止填充时报错
}4.执行我们这个填充文件就可以生成填充数据
php artisan db:seed --class=UserSeeder边栏推荐
- 21set classic case
- Win10 system problems
- One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?
- Development of B2B transaction collaborative management platform for kitchen and bathroom electrical appliance industry and optimization of enterprise inventory structure
- Jerry's seamless looping [chapter]
- markdown/LaTeX中在字母下方输入圆点的方法
- 六石管理学:垃圾场效应:工作不管理,就会变成垃圾场
- Jericho After sleep, the system will wake up regularly and continue to run without resetting [chapter]
- 【无标题】
- Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!
猜你喜欢

PgSQL queries the largest or smallest data of a field in a group

leetcode:1504. 统计全 1 子矩形的个数

`Thymeleaf`模板引擎全面解析

Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing
![[leetcode] 10. Regular expression matching](/img/a9/4cdf8d46068a2d7ea6ac212f416157.png)
[leetcode] 10. Regular expression matching

v-for 中 key的作用和原理

MySQL log management, backup and recovery

探索云原生数据库,纵观未来科技发展

SAP Marketing Cloud 功能概述(三)
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]
随机推荐
Some basic database operations (providing the original database information)
15 differences between MES in process and discrete manufacturing enterprises (Part 2)
Overview of SAP marketing cloud functions (IV)
Daily knowledge popularization
AntD checkbox,限制选中数量
10_那些格調很高的個性簽名
One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?
【无标题】
【LeetCode】10、正则表达式匹配
专精特新“小巨人”再启动,“企业上云”数字赋能
Defoaming
Grendao usage problems
Go语言三个高效编程的技巧
Google waymo proposed r4d: remote distance estimation using reference target
Online text entity extraction capability helps applications analyze massive text data
Jerry's serial port receiving IO needs to set the digital function [chapter]
4个不可不知的“安全左移”的理由
[environment setup] zip volume compression
SaaS management system solution of smart Park: enabling the park to realize information and digital management
在CVS中恢复到早期版本