在 Laravel 5.5 中生成工厂
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47194254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate Factory in Laravel 5.5
提问by abu abu
I ran below command
我运行下面的命令
php artisan make:factory AddressFactory
php artisan make:factory AddressFactory
I am getting below result
我得到低于结果
$factory->define(Model::class, function (Faker $faker) {
$factory->define(Model::class, function (Faker $faker) {
But I would like to get result like below
但我想得到如下结果
$factory->define(App\Address::class, function (Faker $faker) {
$factory->define(App\Address::class, function (Faker $faker) {
What should I do ?
我该怎么办 ?
回答by jedrzej.kurylo
If you want the make:factorycommand to generate a factory class for an existing model, you need to tell it which model to use with the --modeloption:
如果您希望make:factory命令为现有模型生成工厂类,则需要使用--model选项告诉它使用哪个模型:
php artisan make:factory AddressFactory --model="App\Address"