I'm trying to find a way to set a default value for any field (not filled by user input) in Yii2 as to avoid a "Cannot be NULL" database exception.
Is there any way that this could be done?
Cheers.
Yii2 Default Validator - in model validation rules pass all attributes, which you want to be filled with default values, like:
[['attribute', 'second_attribute'], 'default', 'value' => 'something_here'],
You could add the default values to the model database table
Than use loadDefaultValues() when creating an instance of your model
$model = new Post();
$model->loadDefaultValues();