1
数我有一个laravel工厂,看起来像这样:Laravel工厂返回0场,存储在数据库
$factory->define(Municipality::class, function (Generator $faker) {
return [
'name' => $faker->city,
'number' => (int) $faker->numerify('####')
];
});
如果我运行php artisan tinker
和使用工厂这样factory(Acme\Models\Municipality::class)->create
,我得到的输出
=> Acme\Models\Municipality {#797
name: "West Alysaland",
number: 0,
}
当我运行Acme\Models\Municipality::all()
我得到
>>> Municipality::all();
=> Illuminate\Database\Eloquent\Collection {#771
all: [
Acme\Models\Municipality {#798
number: 9449,
name: "Lake Rosemarie",
},
],
}
number
被设置为可在模型中填写,并且该字段在迁移中设置为unsignedInteger
。
有谁知道为什么会发生这种情况?
编辑:
一些调试我发现这事->save()
被称为在模型上后后。