Search code examples
phplaravellaravel-9faker

Array to string conversion error when running laravel 9 faker


In my laravel 9 application, I was trying to create the following faker.

<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
 */
class MemberFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition()
    {
        return [
            "firstname" => $this->faker->name(),
            "lastname" => $this->faker->name(),
            "dateofbirth" => $this->faker->date('YYYY-MM-DD'),
            "summary" => $this->faker->words(100),
            "division_name" => $this->faker->name()
        ];
    }
}

but every time when I try to seed the data, I get the following error,

enter image description here


Solution

    • word // 'aut'
    • words($nb = 3, $asText = false) // array('porro', 'sed', 'magni')
      words return an array
      If you want to use words as text you need to put 2nd param is true