Support the ongoing development of →
Database Eloquent
Last updated 1 year ago.

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.


Last updated 1 year ago.

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.

Last updated 1 year ago.

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.

Last updated 1 year ago.

Do you have something like this in your models:

        foreach ($model->toArray() as $key => $value) {
                $model->{$key} = empty($value) ? null : $value;

        return true;


Last updated 1 year ago.

Finally found the problem.

The problem occurs with float values of 0


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!

Last updated 8 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.