我想播种数据库当我使用这个
I want to seed database when I use this
public function run()
{
$users = factory(appUser::class, 3)->create();
}
在数据库中添加三个用户但是当我使用这个
Add three user in database but when I use this
public function run()
{
$Comment= factory(appComment::class, 3)->create();
}
显示错误
[无效参数异常]
无法找到名称为 [default] [appComment] 的工厂.
[InvalidArgumentException]
Unable to locate factory with name [default] [appComment].
默认情况下,laravel 安装在 database/factories/ModelFactory.php 文件中带有此代码.
By default the laravel installation comes with this code in the database/factories/ModelFactory.php File.
$factory->define(AppUser::class, function (FakerGenerator $faker) {
return [
'name' => $faker->name,
'email' => $faker->email,
'password' => bcrypt(str_random(10)),
'remember_token' => str_random(10),
];
});
因此您需要先定义一个工厂模型,然后再使用它来为数据库做种.这只是使用 Faker Library 的一个实例,它用于生成假数据以播种数据库以执行测试.
So you need to define a factory Model before you use it to seed database. This just uses an instance of Faker Library which is used to generate fake Data for seeding the database to perform testing.
确保您已为评论模型添加了类似的模态工厂.
Make sure You have added a similar Modal Factory for the Comments Model.
所以你的评论模型工厂将是这样的:
So your Comments Model Factory will be something like this :
$factory->define(AppComment::class, function (FakerGenerator $faker) {
return [
'comment' => $faker->sentence,
// Any other Fields in your Comments Model
];
});
这篇关于Laravel 5.2:无法找到名称为 [默认] 的工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
按类别划分的 Magento 产品Magento products by categories(按类别划分的 Magento 产品)
资源被解释为图像但使用 MIME 类型 text/html 传输Resource interpreted as image but transferred with MIME type text/html - Magento(资源被解释为图像但使用 MIME 类型 text/html 传输 - Magen
Magento 中是否有客户帐户注册事件?Is there an event for customer account registration in Magento?(Magento 中是否有客户帐户注册事件?)
Magento addFieldToFilter:两个字段,匹配为 OR,而不是Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:两个字段,匹配为 OR,而不是 AND)
“未找到错误 404"在 Magento 管理员登录页面quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到错误 404在 Magento 管理员登录页面)
在 Magento 中获取订单增量 IDGet Order Increment Id in Magento(在 Magento 中获取订单增量 ID)