Solution when column value becomes NULL even if create is executed in Laravel

Sep 10, 2020 PHP Laravel



** Review the model **

In my case, I didn’t fill in the corresponding column for $ fillable in the model.

class Model extends Authenticatable
    use Notifiable;

    / **
     * The attributes that are mass assignable.
     * @var array
     * /
    protected $ fillable = [
    // (Specify the column that was NULL even if create was executed here)


In Laravel, when saving records etc. in the database using create etc. through the model, a malicious user creates columns etc. without permission and makes an administrator so that that person does not become a virtual administrator A function to protect is provided as standard. Therefore, if you do not specify the column to be created and inserted with create with $ fillable etc., you will think that Laravel may be a malicious user, and automatically insert NULL to protect it. It was the cause.

** Don’t forget to protect columns that do not have default values such as create with $ fillable !! **