Skip to content

something wrong when I use this package #2

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

Open
ChenRuihua opened this issue Jul 4, 2019 · 3 comments
Open

something wrong when I use this package #2

ChenRuihua opened this issue Jul 4, 2019 · 3 comments

Comments

@ChenRuihua
Copy link

I use this package like this:

use DecimalObjectCast;
protected $casts = [
'price' => 'decimal',
'amount' => 'decimal',
];

but have error.

Declaration of Decimal\DecimalObjectCast::asDecimal(Decimal\Decimal $value, $decimals) should be compatible with Illuminate\Database\Eloquent\Model::asDecimal($value, $decimals)

is there have a readme about this package?

@rtheunissen
Copy link
Contributor

Can you install version 1.1.2 and see if there are any issues in your environment?

@Peter-Krebs
Copy link

Have you checked the usage of decimal casts without the package?

See Laravel documentation
Probably the solution to your problem: The Laravel docs say you must specify number of digits for casts to type decimal, for example 'price' => 'decimal:64' instead of just 'decimal'.

See: Laravel Eloquent Mutators: Attribute casting

@barryp
Copy link

barryp commented Jul 3, 2021

Just FYI, for Laravel 7.x and up it might be easier to define a Custom Cast class - with a get() method that converts the null|string value from the DB to a null|Decimal, and a set() method that does the reverse.

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

No branches or pull requests

4 participants