Could not find a four-digit year. No data available.

I am trying to use seeds in Laravel 5.2

My code is dying in User factory:

$factory->define(App\User::class, function (Faker\Generator $faker) { $countries = Countries::all()->pluck('id')->toArray(); return [ 'name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'grade_id' => $faker->numberBetween(1, 5), 'country_id' => $faker->randomElement($countries), 'city' => $faker->city, 'latitude' => $faker->latitude, 'longitude' => $faker->longitude, 'role_id' => $faker->numberBetween(1, 3), 'verified' => true, 'remember_token' => str_random(10), 'provider' => '', 'provider_id' => str_random(5) ]; }); 

Providing me this error:

 A four digit year could not be found Data missing 

I found the reason, but I don’t know how to fix it.

When I call factory, I call it like this:

  factory(User::class)->create(['role_id',2]); 

If I call it this:

  factory(User::class)->create(); 

I do not get any more errors. But I really need to sow different users ...

Any idea ???

+8
source share
3 answers

Have you tried using an array of values ​​by value in the create method:

factory(User::class)->create(['role_id' => 2]);

+29
source

Perhaps I was late for the party, I had the same problem, and it turns out due to the fact that I provided a key with no value in the returned array.

get rid of 'provider' => '' .

As for the cause of the problem, I really don't know, but it has something to do with Carbon

+2
source

I had the same problem when using bulk assignment and it turned out that I forgot to wrap my input array in a query helper function

That is, I had Model :: create ([form input]);

Instead of Model :: create (request ([form input]);

Just if someone comes across this.

0
source

All Articles