-
-
Save codyphobe/530b50c427320ec2f6de to your computer and use it in GitHub Desktop.
NullingTrait.php
This file contains 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