Y
Y
Yuri Kulaxyz2019-12-27 23:59:38
Laravel
Yuri Kulaxyz, 2019-12-27 23:59:38

Why doesn't $fillable work when calling create()?

protected $fillable = [
        'rfid', 'name', 'phone', 'balance', 'email', 'identity_document', 'password', 'verified', 'avatar',
    ];

Here is RegisterController
$values = [
            'name' => $data['name'],
            'email' => $data['email'],
            'phone' => $data['phone'],
            'password' => Hash::make($data['password']),
            'identity_document' => 'storage/images/documents/'.$fileName,
        ];
        return User::create($values);

Here's the error I'm getting:
SQLSTATE[HY000]: General error: 1364 Field 'identity_document' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `phone`, `password`, `updated_at`, `created_at`) values (Yurii Kulaxyz, [email protected], +357939606674, $2y$10$/VONPcRE2.FQ1my1hM1LiOwtU.oWm4rotpY0JNHMU3DkW./1d5WnO, 2019-12-27 15:52:44, 2019-12-27 15:52:44))

When outputting the $values ​​array, I get all the correct data, however, create ignores the identity_document field.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Kulaxyz, 2019-12-28
@Kulaxyz

Understood. The problem was that I am using "mutator method" setIdentityDocumentAttribute($value);
which was not correctly written.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question