If you're familiar with my AASM, then this is a similar take – just implemented in Laravel 5 for Eloquent classes.
composer require mikerice/stateful-eloquent
MikeRice\Stateful\StatefulServiceProvider::class,
Your models should use the Stateful trait and interface
use MikeRice\Stateful\StatefulTrait;
use MikeRice\Stateful\StatefulInterface;
class Transaction extends Model implements StatefulInterface
{
use StatefulTrait;
}
Your models should have an array name $states
that define your model states.
/**
* Transaction States
*
* @var array
*/
protected $states = [
'draft' => ['inital' => true],
'processing',
'errored',
'active',
'closed' => ['final' => true]
];
/**
* Transaction State Transitions
*
* @var array
*/
protected $transitions = [
'process' => [
'from' => ['draft', 'errored'],
'to' => 'processing'
],
'activate' => [
'from' => 'processing',
'to' => 'active'
],
'fail' => [
'from' => 'processing',
'to' => 'errored'
],
'close' => [
'from' => 'active',
'to' => 'close'
]
];
$transaction = new Transaction();
$transaction->process();
$transaction->isProcessing();