Skip to content

Instantly share code, notes, and snippets.

@SDKiller
Created July 12, 2014 22:15
Show Gist options
  • Save SDKiller/d8226e5a0bacc70d913c to your computer and use it in GitHub Desktop.
Save SDKiller/d8226e5a0bacc70d913c to your computer and use it in GitHub Desktop.
public function afterValidate()
{
$schema = static::getTableSchema();
foreach ($this->attributes as $attribute => $value) {
if (!$this->hasErrors($attribute)) {
$typecasted = $schema->getColumn($attribute)->phpTypecast($value);
if ($value !== $typecasted) {
$this->setAttribute($attribute, $typecasted);
}
}
}
return parent::afterValidate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment