1. Go to this page and download the library: Download ilvalerione/state-machine library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ilvalerione / state-machine example snippets
class Order extends Model
{
use HasStateMachine;
...
class Order extends Model
{
use HasStateMachine;
/**
* StateMachine configuration
*
* @return array
*/
protected function stateMachineConfig() : array
{
// This is the name of the graph in the "state-machine.php" config file
return [
'graph' => 'order',
];
}
}
class Order extends Model
{
use HasStateMachine;
/**
* Default model's attributes.
*
* @var array
*/
protected $attributes = [
'status' => 'pending'
];
/**
* StateMachine configuration
*
* @return array
*/
protected function stateMachineConfig() : array
{
// This is the name of the graph in the "state-machine.php" config file
return [
'graph' => 'order',
];
}
}
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'state_machine.transitioning.order.accept' => [
ListenBeforeOrderIsAccepted::class,
],
'state_machine.transited.order.accept' => [
ListenAfterOrderIsAccepted::class,
],
];
}