PHPackages                             norotaro/enumata-recorder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. norotaro/enumata-recorder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

norotaro/enumata-recorder
=========================

Automatically records all Enumata transitions

v1.0.1(2y ago)05MITPHP

Since Aug 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/norotaro/enumata-recorder)[ Packagist](https://packagist.org/packages/norotaro/enumata-recorder)[ RSS](/packages/norotaro-enumata-recorder/feed)WikiDiscussions main Synced yesterday

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Enumata Recorder
================

[](#enumata-recorder)

[![Latest Version](https://camo.githubusercontent.com/2fefdf24f7a5eeccfd6117b31c1b22ade7eda58ed3216c2854c0fc4d9c0e300b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f726f7461726f2f656e756d6174612d7265636f726465722e7376673f6c6162656c3d72656c65617365)](https://packagist.org/packages/norotaro/enumata-recorder)[![Tests](https://github.com/norotaro/enumata-recorder/actions/workflows/test.yaml/badge.svg)](https://github.com/norotaro/enumata-recorder/actions/workflows/test.yaml)

Automatically records all [Enumata](https://github.com/norotaro/enumata) transitions.

Description
-----------

[](#description)

This package allow you to automatically record logs of all states a model with [Enumata](https://github.com/norotaro/enumata) may have and query this logs to take specific actions accordingly.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require norotaro/enumata-recorder
```

Then run the migrations:

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

In a model configured to use **Enumata** ([see documentation](https://github.com/norotaro/enumata#basic-usage)) we only need to add the `LogTransitions` trait:

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

class Order extends Model
{
    use HasStateMachines, LogTransitions;

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

That's it. Now all transitions will be recorded automatically using the `enumata_state_logs` table that was created when installing the package.

Querying Logs
-------------

[](#querying-logs)

Get full history of transitioned states:

```
$order->stateLogs;

// or

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

The stateLogs() method returns an Eloquent relationship that can be chained as any [Query Builder](https://laravel.com/docs/10.x/queries) to further down the results. You also have some scopes available.

```
$order->stateLogs()
    ->fromState(OrderStatus::Pending)
    ->toState(OrderStatus::Approved)
    ->where('created_at', '
