<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tamkeen-tech / laravel-enum-state-machine example snippets
use TamkeenTech\LaravelEnumStateMachine\Traits\HasStateMachines;
class Bill extends Model
{
use HasStateMachines;
protected $fillable = [
'status',
];
protected $casts = [
'status' => BillStatus::class,
];
protected $recordStateHistory = true;
protected $stateMachines = [
'status'
];
}
use TamkeenTech\LaravelEnumStateMachine\Traits\StateMachine;
enum BillStatus: string
{
use StateMachine;
case PENDING = 'PENDING';
case PAID = 'PAID';
case EXPIRED = 'EXPIRED';
case REFUNDED = 'REFUNDED';
public function transitions(): array
{
return match ($this) {
self::PENDING => [self::PAID, self::EXPIRED],
self::PAID => [self::REFUNDED]
};
}
public function initialState(): array
{
return [self::PENDING];
}
}