PHP code example of grazulex / laravel-statecraft

1. Go to this page and download the library: Download grazulex/laravel-statecraft 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/ */

    

grazulex / laravel-statecraft example snippets


use Grazulex\LaravelStatecraft\HasStateMachine;

class Order extends Model
{
    use HasStateMachine;
    
    protected $stateMachine = 'OrderStateMachine';
}

// Create a new order (starts in 'pending' state)
$order = Order::create(['total' => 100.00]);

// Transition to next state
$order->transition('pay'); // Moves to 'paid' state

// Check current state
echo $order->currentState(); // 'paid'
bash
php artisan vendor:publish --tag=statecraft-config
bash
php artisan vendor:publish --tag=statecraft-migrations
php artisan migrate
bash
php artisan statecraft:make OrderStateMachine --model=Order