Replies: 1 comment
-
Here's what i do it now, use Spatie\ModelStates\State;
use Spatie\ModelStates\StateConfig;
abstract class PaymentState extends State
{
public static function config(): StateConfig
{
return parent::config()
->default(Pending::class)
->allowTransition(Pending::class, Paid::class)
->allowTransition(Pending::class, Failed::class)
;
}
public function asEnum($enum)
{
return $enum::tryFrom($this->getValue());
}
} Then on the model use Spatie\ModelStates\HasStates;
class Payment extends Model
{
use HasStates;
protected $casts = [
'state' => PaymentState::class,
];
public function canBeRefund(): bool
{
return match($this->state->asEnum(PaymentStatus::class){
// list enums values
}
{
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to use enum together with this package? My use case is, i want to ensure all states are covered when doing
match
Something like
Order::getStates()->asEnum(OrderStatus::class)
which will then be use inBeta Was this translation helpful? Give feedback.
All reactions