-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
Use HasAttributes::originalIsEquivalent() for attribute change detection #971
Comments
Does that work with attribute casting as well? I was just playing with state attribute which is casted to ModelState and got it working by adding this to LogsActivity trait's attributeValuesToBeLogged function: if ($old instanceof Spatie\ModelStates\State && $new instanceof Spatie\ModelStates\State) {
return $old->equals($new) ? 0 : 1;
} I think there should be some generic way to handle all casted attributes. |
@azurinspire no, it has a lot of cases but none for custom casts - these will fall back to I think it would help if we move the current diff-check callback to its own method and write it that you can easily override and extend it. laravel-activitylog/src/Traits/LogsActivity.php Lines 289 to 304 in 334e742
public function foobar(): int
{
$foo = parent::foobar();
if ($old instanceof Spatie\ModelStates\State && $new instanceof Spatie\ModelStates\State) {
return $old->equals($new) ? 0 : 1;
}
return $foo;
} (intentionally used But such a change would help allow you to adjust the value comparison without overriding the whole surrounding method!? |
@Gummibeer sounds good solution to me |
Found the
\Illuminate\Database\Eloquent\Concerns\HasAttributes::originalIsEquivalent()
method during code diving and it should be usable for our trait! 🎉This PR would be mainly reasearch when that method was added, if it's compatible with our version support rules and switching our own change detection logic with the core one.
The text was updated successfully, but these errors were encountered: