Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brick\Math\Exception\NumberFormatException The given value "" does not represent a valid number. #51991

Closed
dukmaurice opened this issue Jul 2, 2024 · 5 comments

Comments

@dukmaurice
Copy link

Laravel Version

11.10.0

PHP Version

8.2.14

Database Driver & Version

MySQL 8.0.36

Description

Cast decimal attribute fails if model already exist on database

Steps To Reproduce

Suppose we have a model Address like:

class Address extends Model
{
     protected $casts = [
         'latitude' => 'decimal:10',
         'longitude' => 'decimal:10',
    ];
}

Work only if Model doesn't exist on Database:

$address = Address::firstOrNew([
   'code' => 'xxx'
]);

$address->latitude = "";
$address->longitude = "";
$address->save();

Don't work:

$address = Address::updateOrCreate([
   'code' => 'xxx'
], [
   'latitude' => "",
   'longitude' => ""
]);
Copy link

github-actions bot commented Jul 2, 2024

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@dukmaurice
Copy link
Author

dukmaurice commented Jul 2, 2024

#51996

@developeralamin
Copy link

If you have a specific default value for latitude and longitude, you can set them accordingly

$defaultLatitude = 0.0; // or any default value you prefer
$defaultLongitude = 0.0; // or any default value you prefer

$address = Address::updateOrCreate([
   'code' => 'xxx'
], [
   'latitude' => $defaultLatitude,
   'longitude' => $defaultLongitude
]);

@chu121su12
Copy link
Contributor

Maybe the author wanted the same behavior on creation vs update. In this case since the related PR was closed, the alternative is to make create method throws.

@driesvints
Copy link
Member

Looks like we're not going to make any changes here right now sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants