Support the ongoing development of Laravel.io →
Database Eloquent Testing

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"
  ]
Last updated 3 years ago.
0

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

0

I do not hit the database since I'm using make() instead of create. Anyway the field is of type varchar thus correct.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

gambledor gambledor Joined 11 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.