Created
June 18, 2015 05:57
-
-
Save dwightwatson/0d3ccfcc447dbd0a7514 to your computer and use it in GitHub Desktop.
NullingTrait.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Support; | |
trait NullingTrait | |
{ | |
/** | |
* Boot the trait. Adds an observer class for nulling. | |
* | |
* @return void | |
*/ | |
public static function bootNullingTrait() | |
{ | |
static::saving(function($model) { | |
foreach($model->getAttributes() as $key => $value) { | |
if ($value === '') { | |
$model->setAttribute($key, null); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment