I'm set all empty fields to null
when saving
Using OctoberCMS model event beforeSave
(equivalent to Laravel model saving)
public function beforeSave()
{
// $this => the model
foreach ( $this->toArray() as $name => $value )
{
if ( empty( $value ) ) {
$this->{$name} = null;
}
}
}
The problem is when field has a default value defined on database (mysql), for example:
$table->integer('value')->default(1);
I need to get an array of all nullable or not nullable fields of current model.
How do this?