laravel-eloquent-state-machines icon indicating copy to clipboard operation
laravel-eloquent-state-machines copied to clipboard

Models not implementing HasStateMachines trait no longer support having a scopeStatus method.

Open CaptainHilly opened this issue 4 years ago • 2 comments

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:

  1. Create ModelA with a scopeStatus method. The method can be a no-op, it doesn't matter.
  2. Create ModelB implementing HasStateMachines.
  3. Try call ModelA::status()->first();
  4. 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!!!

CaptainHilly avatar Dec 28 '20 01:12 CaptainHilly

If following the interim solution mentioned above, don't forget to find uses of ::status(), cause.... I forgot.... and broke production :-)

CaptainHilly avatar Dec 28 '20 02:12 CaptainHilly

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! 😅

asantibanez avatar Dec 28 '20 03:12 asantibanez