学习Laravel并在尝试在命令行上使用工厂时出现此错误:
PHP warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in /Applications/MAMP/htdocs/breedr-laravel/vendor/laravel/framework/src/Illuminate/Support/helpers.php on line 671
工厂代码是这样的:
$factory->define(App\Gecko::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'aquisition_date' => $faker->date($format = 'Y-m-d', $max = 'now'),
'morph' => $faker->word,
'sex' => $faker->word,
'genetics' => $faker->word,
'bio' => $faker->paragraphs(3),
'bred' => $faker->numberBetween(0, 1),
'hatchling' => $faker->numberBetween(0, 1),
'clutch' => $faker->randomDigitNotNull,
'image' => 'image.jpg',
'user_id' => $faker->randomDigitNotNull,
];
});
当我运行$gecko = factory('App\Gecko')->make();
时,它在终端上加载没问题,但是当我运行$gecko = factory('App\Gecko')->create();
时,我只是得到了上面的错误。
我对此很新,不明白问题所在。如果我错过了重要的代码,请告诉我!
答案 0 :(得分:3)
好的,这是一个非常简单的修复。我只需要改变:
'bio' => $faker->paragraphs(3),
至
'bio' => $faker->paragraphs(3, true),
现在它绝对正常:)