marbobo's avatar
Level 12

[ErrorException: Array to string conversion] when running ModelFactory

Has anyone have an idea why I get this error below? Im kind of stuck right now. All I have done is just run a model factory.

ErrorException: Array to string conversion

/home/apps/www/vendor/illuminate/support/Str.php:560
/home/apps/www/vendor/illuminate/database/QueryException.php:57
/home/apps/www/vendor/illuminate/database/QueryException.php:40
/home/apps/www/vendor/illuminate/database/Connection.php:693
/home/apps/www/vendor/illuminate/database/Connection.php:652
/home/apps/www/vendor/illuminate/database/Connection.php:486
/home/apps/www/vendor/illuminate/database/Connection.php:438
/home/apps/www/vendor/illuminate/database/Query/Processors/Processor.php:32
/home/apps/www/vendor/illuminate/database/Query/Builder.php:2963
/home/apps/www/vendor/illuminate/database/Eloquent/Builder.php:1617
/home/apps/www/vendor/illuminate/database/Eloquent/Model.php:1124
/home/apps/www/vendor/illuminate/database/Eloquent/Model.php:1089
/home/apps/www/vendor/illuminate/database/Eloquent/Model.php:930
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:275
/home/apps/www/vendor/illuminate/collections/Traits/EnumeratesValues.php:235
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:278
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:236
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:416
/home/apps/www/vendor/illuminate/collections/Collection.php:642
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:424
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:364
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:348
/home/apps/www/vendor/illuminate/database/Eloquent/Concerns/GuardsAttributes.php:151
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:353
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:321
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:233
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:416
/home/apps/www/vendor/illuminate/collections/Collection.php:642
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:424
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:364
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:348
/home/apps/www/vendor/illuminate/database/Eloquent/Concerns/GuardsAttributes.php:157
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:353
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:331
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:332
/home/apps/www/vendor/illuminate/database/Eloquent/Factories/Factory.php:233
/home/apps/www/tests/Unit/TestFactory.php:26

here is how I run the Factory $codeNames = CodeName::factory()->count(3)->create();

and my factory definition is somehing like this.

    public function definition()
    {
        return [
            'status_code_no' => StatusCode::factory(),
            'name' => $this->faker->word(),
            'is_use' => true,
            'matopm => "KR",
        ];
    }
0 likes
3 replies
automica's avatar

@kdev

if you want the status_code_number, you should be doing

 'status_code_no' => StatusCode::factory()->create()->code // or whatever your field is called.
1 like
marbobo's avatar
Level 12

figure out the issue. it was on the faker.. i thought that $this->faker->words(3) will give a string with 3 words but it gives an array.

1 like
automica's avatar

so something not related to the factory you posted?

Please or to participate in this conversation.