Andy Holmes
Andy Holmes

Reputation: 8047

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!

Upvotes: 3

Views: 2278

Answers (1)

Andy Holmes
Andy Holmes

Reputation: 8047

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 :)

Upvotes: 3

Related Questions