In my testcase when I try to create a model by factory like the following
$factory->defineAs(App\Models\Permission::class, 'create_user', function (Faker\Generator $faker) {
return [
'name' => "create_user ",
'display_name' => 'user creation',
'description' => 'She is able to create a new user',
'created_at' => '2015-10-06 13:37:26',
'updated_at' => '2015-10-06 13:37:26'
];
});
where 'name' is my primary key, the factory does not value it with the value I've assigned ('create_user') but with 0 (zero). Here there is its dump
#attributes: array:5 [
"name" => 0
"display_name" => "user creation"
"description" => "She is able to create a new user"
"created_at" => "2015-10-06 13:37:26"
"updated_at" => "2015-10-06 13:37:26"
]
I would first check if name column in the database is of type string, and then if it added to the $fillable so you can mass assign it. Hope it helps
I do not hit the database since I'm using make() instead of create. Anyway the field is of type varchar thus correct.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community