Tuesday, May 23, 2017

laravel seeder array to string conversion

I have a model factory like this

$factory->define(App\Sale::class, function (Faker\Generator $faker) {
return [
    'unit' => $faker->randomDigit,
    'street_no' => $faker->randomDigit,
    'street_name' => $faker->streetName,
    'street_type' => $faker->streetSuffix,
    'suburb' => $faker->randomElements(['Melton South','Melton West','Rye']),
    'postcode' => $faker->numberBetween($min=1000, $max=4000),
    'sale_date' => $faker->dateTimeThisYear,
];
});

Database seeder runs it

factory(App\Sale::class, 5)->create();

The problem is when i run it php artisan db:seed I'm getting the error

  [Illuminate\Database\QueryException]
  Array to string conversion (SQL: insert into `sales` (`unit`, `street_no`,
  `street_name`, `street_type`, `suburb`, `postcode`, `sale_date`, 
`updated_at`, `created_at`) 
values (7, 1, Labadie Centers, Bridge, Rye, 3758, 2016-08-12 1
  5:02:07, 2017-05-23 13:16:56, 2017-05-23 13:16:56))

The error sql doesnt show any arrays that i can see.

When i pasted that sql into my db app and ran it, in order to make it work i had to quote all the strings, but laravel docs dont say anything about that when using faker ? Am I missing something in the model factory ?

exi



via yoyoma

Advertisement