Home » Php » A four digit year could not be found Data missing

A four digit year could not be found Data missing

Posted by: admin November 29, 2017 Leave a comment

Questions:

I’m trying to seed using factories in Laravel 5.2

My code dies in the 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)

];
});

Giving me this error:

A four digit year could not be found   Data missing

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

When I call the factory, I call it like that:

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

If I call it like that:

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

I get no more error.
But I really need to seed different kind of users…

Any idea???

Answers:

have you tried using key value array in the create method:

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

Questions:
Answers:

I might be late to the party, I was having the same problem and it turns out its because I provided a key without a value in the array returned.

get rid of 'provider' => ''.

As to the cause of the problem i really don’t know but it has something to do with Carbon