PHP code example of norotaro / enumata-recorder

1. Go to this page and download the library: Download norotaro/enumata-recorder 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/ */

    

norotaro / enumata-recorder example snippets


use Norotaro\Enumata\Traits\HasStateMachines;
use Norotaro\EnumataRecorder\Traits\LogTransitions;

class Order extends Model
{
    use HasStateMachines, LogTransitions;

    protected $casts = [
        'status' => OrderStatus::class,
    ];
}

$order->stateLogs;

// or

$order->stateLogs()->get();

$order->stateLogs()
    ->fromState(OrderStatus::Pending)
    ->toState(OrderStatus::Approved)
    ->where('created_at', '<', Carbon::yesterday())
    ->get();

$order->stateLogs()->fromState(OrderStatus::Pending)->get();

$order->stateLogs()->toState(OrderStatus::Approved)->get();

use Norotaro\Enumata\Traits\HasStateMachines;
use Norotaro\EnumataRecorder\Traits\LogTransitions;

class Order extends Model
{
    use HasStateMachines, LogTransitions;

    protected $casts = [
        'status'      => OrderStatus::class,
        'fulfillment' => OrderFulfillment::class,
    ];
}

$order->stateLogs()->forField('status')->get();

$order->stateLogs()->forField('fulfillment')->get();

$order->stateLogs('status')->get();

$order->stateLogs('fulfillment')->get();

composer run test
bash
php artisan migrate