Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 - preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

Learning Laravel and when trying to use a factory on the command line i get this error:

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

The factory code is this:

$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,
    ];
});

When I run $gecko = factory('App\Gecko')->make(); it loads on the terminal no problem, but when I run $gecko = factory('App\Gecko')->create(); I just get the error above.

I'm very new to this and don't understand what the problem is. If i've missed important code please let me know!

like image 337
Andy Holmes Avatar asked Feb 18 '26 18:02

Andy Holmes


1 Answers

Okay so it's a really simple fix. I just needed to change:

'bio' => $faker->paragraphs(3), to 'bio' => $faker->paragraphs(3, true),

And now it works absolutely fine :)

like image 107
Andy Holmes Avatar answered Feb 21 '26 14:02

Andy Holmes