This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
ndcisiv
I have extended the User Model to add a few fields to the users table in my plugins boot() method. One of the fields is an integer that is nullable. However, if I try to save the user on the backend and do not supply a value in that field, I get an error. I know I could solve it if I had my own model by implementing the Nullable Trait, but how do I that in my plugin file without an available Nullable Behavior?
daftspunky
Hi ndcisiv,
This behavior doesn't exist because it is simple to make a field nullable by extension. Here is an example:
User::extend(function($model) {
$model->bindEvent('model.beforeSave', function () use ($model) {
if (empty($model->my_attr)) {
$model->attributes['my_attr'] = null;
}
});
});
1-2 of 2