pelmered / filament-money-field

Money field powered by Money PHP
MIT License
54 stars 20 forks source link

How to implement the cast? #9

Closed jinbatsu closed 7 months ago

jinbatsu commented 8 months ago

How to cast the value? Because, the default is saved in database with extra 00. And in the edit or view page, it is not devided by 100.

I though it is already automated by MoneyInput ?

jinbatsu commented 8 months ago

I solved for a moment forced devide 100 using Attribute Model. So every request get value is devided by 100. And MoneyInput now display correct result.

    protected function sampleSalary(): Attribute
    {
        return Attribute::make(
            get: fn (string $value) => $value > 0 ? $value/100 : 0,
        );
    }
pelmered commented 7 months ago

Great that you found a solution. Yes, this should probably be easier and more clear. At least some documentation should be added for this.

jinbatsu commented 7 months ago

OK, thanks.. it means we do not need to force devide 100 in the model anymore.