laravel 找不到四位数年份 数据丢失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34965831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:05:33  来源:igfitidea点击:

A four digit year could not be found Data missing

phplaravellaravel-seeding

提问by Juliatzin

I'm trying to seed using factories in Laravel 5.2

我正在尝试在 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???

任何的想法???

回答by jakehallas

have you tried using key value array in the createmethod:

您是否尝试过在create方法中使用键值数组:

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

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

回答by James Dube

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' => ''.

摆脱'provider' => ''.

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

至于问题的原因我真的不知道,但它与碳有关

回答by Ιησο?? του ναυ?

I recently encounter the same problem, lately I found out that the only problem is I put an invalid value to the timestamp column type.

我最近遇到了同样的问题,最近我发现唯一的问题是我给时间戳列类型设置了一个无效值

In my case I have column email_verified_at [timestamp]. I miss understood I put a string like [email protected]instead of date values, it should be now().

就我而言,我有 column email_verified_at [timestamp]。我想知道我放了一个字符串[email protected]而不是日期值,它应该是now().

回答by seyyedali

how get day difference between carbon and persion time in laravel

如何在laravel中获得碳和人时间之间的天差

回答by F KIng

I had the same issue when using mass assignment and it turned I had forgotten to wrap my array of inputs in the request helper function

我在使用批量赋值时遇到了同样的问题,结果我忘记将我的输入数组包装在请求帮助函数中

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

那就是我有 Model::create([表单输入]);

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

而不是 Model::create(request([表单输入]);

Just incase someone comes across it.

以防万一有人遇到它。