pelmered / filament-money-field

Money field powered by Money PHP
MIT License
40 stars 19 forks source link

Fix "Argument must be of type string, Closure given" error #24

Closed dev-idkwhoami closed 2 months ago

dev-idkwhoami commented 2 months ago

Problem

When supplying the currency() or the locale() function on the HasMoneyAttributes trait it throws an error because the supplied Closure is directly given to the Currency constructor which only takes a string argument.

Solution

Using the $this->evaluate() function to first evaluate the result of the closure and then give it to the constructor. In the case of locale() the evaluation is necessary because protected string $locale is type-hinted to be a string which would also throw an error.

Convention

Every trait in Laravel, Filament that starts with Has is pascal case. Since that wasn't the case here i changed it as well.

dev-idkwhoami commented 2 months ago

I tried to get "Scrutinizer" to successfully run but it seems somewhere I did something wrong.

pelmered commented 2 months ago

Looks good. Thank you!