Giter Club home page Giter Club logo

laravel-state-machine's Introduction

Laravel State Machine

Latest Version on Packagist Total Downloads run-tests

This package helps you to create State Machine data model-based services.

Installation

You can install the package via composer:

composer require caner/state-machine  

Usage

In config/app.php;

\Caner\StateMachine\StateMachineServiceProvider::class,  

and publish config file;

php artisan vendor:publish --tag=caner-state-machine-config  

Step by step documentation

Introducing Concept

A state machine is a mathematical abstraction used to design algorithms. A state machine reads a set of inputs and changes to a different state based on those inputs.

A state is a description of the status of a system waiting to execute a transition. A transition is a set of actions to execute when a condition is fulfilled or an event received. In a state diagram, circles represent each possible state and arrows represent transitions between states.

Basically, we are building a state for each status and running related transition when changing the status.

Sample State Change Workflow

Each Transition should consist of 3 parts. These are the guards, action and afterActions methods.

Sample Transition Workflow

I prefer to use package in complex status changes.

Preferred Directory Tree;

  • app
    • Services
      • YourStateMachine
        • AfterActions
        • Guards
        • States
        • Transitions
        • YourStateMachine.php
      • AnotherStateMachine
        • AfterActions
        • Guards
        • States
        • Transitions
        • AnotherStateMachine.php

In future versions, we will be added, create state machine parts in artisan commands. This time commands run like this directory tree.

1-) Create First State Machine
2-) Create First State
3-) Create First Transition
4-) Create First Guard
5-) Create First AfterAction
6-) Example Transition in Created State Machine
7-) Create Another State Machine

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please create an issue on github issues section.

Credits

Special thanks for Tarfin Labs

License

The MIT License (MIT). Please see License File for more information.

laravel-state-machine's People

Contributors

canerergez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

baobd hsndmr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.