sglara liked this thread
replied to similar post from the same era and author also:
we're having this issue.
on save(), laravel is changing our value of 0 to NULL. Any suggestions or ideas as to why and how we can stop that would be greatly appreciated.
Thanks.
Bumping this because it's killing us. We have a number of columns where the INT value is 0 and on save() laravel is changing them to NULL. Since our column in mysql is set to not null, it's kicking an error. As mentioned by the original post, the value is 0 when it hits save(). Something is happening in save() that is changing the value.
We've tried running the data through a little method to change NULL to DB::raw('DEFAULT'), and that works great for NULL values. The problem is, the value isn't NULL. It's 0. And we want it to be 0. save() is changing 0 to NULL.
Any thoughts, ideas, or suggestions are greatly appreciated.
I'm guessing this is only a Laravel 5 issue, because I find it hard to believe other people wouldn't have run into this a million times with 4. We're going back to 4. I'll let you know.
Do you have something like this in your models:
static::saving(function($model){
foreach ($model->toArray() as $key => $value) {
$model->{$key} = empty($value) ? null : $value;
}
return true;
});
???
Finally found the problem.
The problem occurs with float values of 0
so:
Model::find( 1 )->update( [ 'value' => floatval(0) ] ); // saves null
Model::find( 1 )->update( [ 'value' => intval(0) ] ); // saves 0
So the problem lies with the floats!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community