sebdesign / laravel-state-machine

Winzou State Machine service provider for Laravel
MIT License
327 stars 57 forks source link

pass additional data when applying a transition #31

Closed MartinP7r closed 4 years ago

MartinP7r commented 4 years ago

I was trying to figure out how to set variable data on the model when applying state changes.
E.g. within an application, a user can set the state of a certain model to scheduled and pass a date along with it. the date gets set in a different variable on the model, logic for that could be handled inside the callbacks, as long as there would be a way to pass more args with apply() (currently it seems like only object, event and a static string is possible?)

sebdesign commented 4 years ago

Hey,

After some thought I don't this it's possible to pass other data to callbacks. But after checking symfony/workflow, they do allow passing a context array when applying transitions. I will try to implement that and I'll get back to you!

sebdesign commented 4 years ago

I've tagged v2.1.0 which allows to pass additional data when checking/applying transitions.

You can read more in the Context section of the README. Let me know if that is working well for you case!

MartinP7r commented 4 years ago

Wow, thanks so much for the swift implementation!
I'll go check it out right away 🙂