2017 © Pedro Peláez
 

library eloquent-status-recorder

Eloquent model's status management with history

image

aventure-cloud/eloquent-status-recorder

Eloquent model's status management with history

  • Friday, January 12, 2018
  • by valerione
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

Eloquent Status Recorder

Latest Stable Version Total Downloads License, (*1)

Any eloquent model can have Status management with just one trait. Declare status statically but store status history four your models in the database., (*2)

Install

composer require aventure-cloud/eloquent-status-recorder, (*3)

Config

Publish configuration file in your project:, (*4)

php artisan vendor:publish --provider="AventureCloud\EloquentStatusRecorder\EloquentStatusRecorderServiceProvider" --tag="config", (*5)

Migration

We provide a migration script to create statuses table. To publish migration script execute:, (*6)

php artisan vendor:publish --provider="AventureCloud\EloquentStatusRecorder\EloquentStatusRecorderServiceProvider" --tag="migrations", (*7)

And run with artisan command:, (*8)

php artisan migrate --path=/database/migrations, (*9)

Use

Attach HasStatus trait to your models and configure statuses values for each models indipendently., (*10)

class Order extends Model {
    use HasStatus;

    protected $statuses = [
        'opened'    => [],
        'paid'      => ['from'     => 'opened'],
        'approved'  => ['from'     => 'paid'],
        'shipped'   => ['from'     => ['paid', 'approved']],
        'arrived'   => ['from'     => 'shipped'],
        'cancelled' => ['not-from' => ['arrived']],
    ];
}

Utility methods

$order = Order::find(1);

/* 
 * Current status
 * instance of model configured in config('eloquent-status-recorder.status_model')
 */
$order->status;

/* 
 * List of all available statuses for current model
 */
$order->statuses();

/* 
 * Available statuses after current status value based on "from" and "not-from" rules
 */
$order->nextAvailableStatuses();

/* 
 * Change status
 */
$order->changeStatusTo('shipped');

Auto-run callbacks

In some cases, you need to do something after a specific status is set. For example, send an mail after an order is "shipped". This package invokes a method after status change by the convention of on + status_name (camel cased):, (*11)

class Order extends Model {
    use HasStatus;

    protected $statuses = [
        'opened'    => [],
        'paid'      => ['from'     => 'opened'],
        'approved'  => ['from'     => 'paid'],
        'shipped'   => ['from'     => ['paid', 'approved']],
        'arrived'   => ['from'     => 'shipped'],
        'cancelled' => ['not-from' => ['arrived']],
    ];

    public function onShipped()
    {
        // Send email to the user
    }
}

Events

Every time a status change happen two event will fire with attached the current eloquent model instance and the given status: - StatusChanging (Before status is saved) - StatusChanged (After status change is performed), (*12)

The Versions

12/01 2018

dev-master

9999999-dev

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

12/01 2018

0.0.7

0.0.7.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

12/01 2018

dev-develop

dev-develop

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

12/01 2018

0.0.6

0.0.6.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

11/01 2018

0.0.5

0.0.5.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

09/01 2018

0.0.4

0.0.4.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

09/01 2018

0.0.3

0.0.3.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

09/01 2018

0.0.2

0.0.2.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

09/01 2018

0.0.1

0.0.1.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

21/12 2017

0.0.9

0.0.9.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status

17/12 2017

0.0.8

0.0.8.0

Eloquent model's status management with history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Valerio Barbera

laravel eloquent status