Closed denisgoryaynov closed 2 years ago
Hi Denis, thanks for your issue report.
Does it work when using (string) $value === $expected
on line 64 of AttributeEvents
?
If that doesn't work, can you reproduce the issue on a PHPSandbox notebook? So I can look into it.
Hi, casting with (string) $value === $expected
produces the expected result
Thanks, I'll work on a way to support all castables.
I've added support for Castables in v1.2.0. This should fix your problem :)
When casting attributes with
protected $casts = []
the changes are not picked up and the relative events are not fired, for example I am using spatie/laravel-model-states to keep the status of a request with the following $casts:And the following $dispatchesEvents:
In this case the events are not fired because the Trait
AttributeEvents
compares the values like this on line 64: $value === $expected, but because of the cast my value is not a string but an instance of a RequestStatus. Comparing the values with $value == $expected works because the RequestStatus can be cast to a string. I tried adding$this->castAttribute($attribute, $expected)
but I keep getting the current value of the attribute and not the $expected value I want to cast, I don't know if it's how laravel is supposed to work. For now I ended up doing$value = $this->getAttributes()[$attribute];
on line 32 and I get the expected resault