laravel-eloquent-state-machines
laravel-eloquent-state-machines copied to clipboard
Models not implementing HasStateMachines trait no longer support having a scopeStatus method.
Describe the bug Models that do not implement HasStateMachines, and have a scopeStatus method, will throw a 'call to undefined method status()' exception.
To Reproduce Steps to reproduce the behavior:
- Create ModelA with a scopeStatus method. The method can be a no-op, it doesn't matter.
- Create ModelB implementing HasStateMachines.
- Try call ModelA::status()->first();
- Be sad
Expected behavior The call to ModelA::status()->first() should not throw a method not found exception.
Solution Ideas Presume the registering of the status macro in boot of HasStateMachines is causing the issue but not had much of a dig.
Obviously not an issue for new applications making use of this package, but very problematic for existing apps with many models implementing legacy status management, as is the case with our application.
An interim solution for any reader of this Issue is to find/replace all uses of ->status() with something like ->legacyStatus() and change scopeStatus to scopeLegacyStatus.
Love the package BTW. Well done legends!!!
If following the interim solution mentioned above, don't forget to find uses of ::status(), cause.... I forgot.... and broke production :-)
Hey @CaptainHilly ! Thank you for trying out the package.
Yes! I am aware of the status()
issue. I've ran into the same problem myself. I am thinking of adding a prefix/suffix
to these helper methods that can be customized via config
. Eg: suffix => 'StateMachine'
, method statusStateMachine()
How does that sound to you?
Be careful with production! 😅