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

Get possible states for a given state

Open aeq-dev opened this issue 3 years ago • 1 comments

Summary

What's the new feature about? What should it do?

return [
        'pending' => ['approved', 'declined'],
        'approved' => ['processed'],
    ];

I need to know which states are allowed to be executed for a given state, Something like this: array = $model->status->allowedStatesToBeAppliedOn('approved'); // => this gives ['processed']

Additional Notes

This may be usefull for UI/UX, when we view a model record, we may show a button actions to perform one of its allowed states to be applied.

Thanks

aeq-dev avatar Dec 11 '21 01:12 aeq-dev

As a solution for me, I did this in my model :

    public function allowedStates()
    {
        return $this->status()->stateMachine()->transitions()[$this->status];
    }

aeq-dev avatar Dec 11 '21 10:12 aeq-dev