You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a custom transition class, which I have defined in my state config, that accepts a second argument (userId). The issue is that anytime I use ->transitionableStates() on my primary model, it throws this error:
Too few arguments to function App\Models\States\Payable\Transitions\DraftToConfirmed::__construct(), 1 passed in /var/www/html/vendor/spatie/laravel-model-states/src/State.php on line 299 and exactly 2 expected
To me the transitionableStates is one of the most useful features of the package, so I want to make sure I'm using it correctly. I assume it's instantiating the transition class to check the canTransition when retrieving transitionable states. I can get around it by making the second argument nullable in the custom transition class, but that doesn't seem like a good solution if it should be required when the transition class is actually used.
My canTransition method on the custom class is not affected by the argument, but if it were, the transitionableStates couldn't return correctly even if we got around the above issue. That should probably be documented, or there could be an exception thrown that arguments on custom classes can't be required if also using the transitionableStates method.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've got a custom transition class, which I have defined in my state config, that accepts a second argument (userId). The issue is that anytime I use ->transitionableStates() on my primary model, it throws this error:
To me the transitionableStates is one of the most useful features of the package, so I want to make sure I'm using it correctly. I assume it's instantiating the transition class to check the canTransition when retrieving transitionable states. I can get around it by making the second argument nullable in the custom transition class, but that doesn't seem like a good solution if it should be required when the transition class is actually used.
My canTransition method on the custom class is not affected by the argument, but if it were, the transitionableStates couldn't return correctly even if we got around the above issue. That should probably be documented, or there could be an exception thrown that arguments on custom classes can't be required if also using the transitionableStates method.
Beta Was this translation helpful? Give feedback.
All reactions