Option to enforce state machine even when updating the record #212
jigar-dhulla
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently,
\Spatie\ModelStates\Exceptions\TransitionNotFound
is triggered only when something like$payment->state->transitionTo(Paid::class);
is used. This works just perfect.Now, according to me and my team, even following should have thrown
TransitionNotFound
exception, but it is working.I understand that technically we are not transitioning but updating the record so package is working as expected.
But logically it should be restricted, I personally think.
We wanted to have this restriction in place for developers(esp. future) as well.
As of now, we have solved this by using the combination of
PaymentObserver
'supdating()
method andcanTransitionTo()
.Snippet from PaymentObserver:
Let me know if I have overcomplicated simple thing and there is a better way to achieve this.
Also, If this is something that can be part of the package I can think more on this and work on raising a PR to add this behavior optionally. On top of my mind I can think of having a new optional trait
EnforceStateTransitionsWhenUpdating
Beta Was this translation helpful? Give feedback.
All reactions