当前位置:网站首页>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边栏推荐
猜你喜欢
随机推荐
Google waymo proposed r4d: remote distance estimation using reference target
`Thymeleaf`模板引擎全面解析
Puzzle (016.2) finger painting Galaxy
Grendao usage problems
The difference between V-IF and v-show
Digital business cloud: strengthen supplier management and promote efficient collaboration between air transport enterprises and suppliers
打败 二叉树!
How to avoid placing duplicate orders
Linux 安装 CenOS7 MySQL - 8.0.26
Redis interview questions
Maximum path sum in binary tree [handle any subtree, then handle the whole tree]
【从零开始学zabbix】一丶Zabbix的介绍与部署Zabbix
SaaS management system solution of smart Park: enabling the park to realize information and digital management
v-for 中 key的作用和原理
MES在流程和离散制造企业的15个差别(下)
Jerry has opened a variety of decoding formats, and the waiting time from card insertion to playback is long [chapter]
第八章 操作位和位串(四)
leetcode:1504. 统计全 1 子矩形的个数
Win10 system problems
[deep learning] storage form of nchw, nhwc and chwn format data









