public function setNullValues() { foreach ($this->fillable as $field) { if (strstr($field, '_id') && !$this->{$field}) { $this->{$field} = null; } } }