Code Monkey home page Code Monkey logo

laravel-eloquent-flag's Introduction

Laravel Eloquent Flag

cog-laravel-eloquent-flag

Releases Build Status StyleCI Code Quality License

Introduction

Eloquent boolean & timestamp flagged attributes behavior. Enhance Eloquent Models with commonly used state flags like Active, Published, Approved and others in a minutes!

Contents

Features

Available flags list

Trait name Logic Database column Flag type Conflict
HasAcceptedAt Classic accepted_at Timestamp HasAcceptedFlag
HasAcceptedFlag Classic is_accepted Boolean HasAcceptedAt
HasActiveFlag Classic is_active Boolean -
HasApprovedAt Classic approved_at Timestamp HasApprovedFlag
HasApprovedFlag Classic is_approved Boolean HasApprovedAt
HasArchivedAt Inverse archived_at Timestamp HasArchivedFlag
HasArchivedFlag Inverse is_archived Boolean HasArchivedAt
HasClosedAt Inverse closed_at Timestamp HasClosedFlag
HasClosedFlag Inverse is_closed Boolean HasClosedAt
HasDraftedAt Inverse drafted_at Timestamp HasDraftedFlag
HasDraftedFlag Inverse is_drafted Boolean HasDraftedAt
HasEndedAt Inverse ended_at Timestamp HasEndedFlag
HasEndedFlag Inverse is_ended Boolean HasEndedAt
HasExpiredAt Inverse expired_at Timestamp HasExpiredFlag
HasExpiredFlag Inverse is_expired Boolean HasExpiredAt
HasInvitedAt Classic invited_at Timestamp HasInvitedFlag
HasInvitedFlag Classic is_invited Boolean HasInvitedAt
HasKeptFlag Classic is_kept Boolean -
HasPublishedAt Classic published_at Timestamp HasPublishedFlag
HasPublishedFlag Classic is_published Boolean HasPublishedAt
HasVerifiedAt Classic verified_at Timestamp HasVerifiedFlag
HasVerifiedFlag Classic is_verified Boolean HasVerifiedAt

Any entity can has more than one flag at the same time. If flags can't work for the same entity simultaneously they are listed in Conflict column.

How it works

Eloquent Flag is an easy way to add flagged attributes to eloquent models. All flags has their own trait which adds global scopes to desired entity.

There are 2 types of flags:

  • Boolean flags are the common ones. Stored in database as BOOLEAN or TINYINT(1) value.
  • Timestamp flags represented in database as nullable TIMESTAMP column. Useful when you need to know when action was performed.

All flags separated on 2 logical groups:

  • Classic flags displays only entities with true or timestamp flag value by default.
  • Inverse flags displays only entities with false or null flag value by default.

Omitted entities could be retrieved by using special global scope methods, unique for each flag.

Example: If your Article model has PublishedAt flag then Article::get() will return you only published records. When you need to get only unpublished records you could call Article::onlyUnpublished()->get() and Article::withUnpublished()->get() will return you published and unpublished articles as well.

Helper traits will automatically cast flag attributes to a DateTime / Carbon instance or bool for you.

Installation

Pull in the package through Composer.

$ composer require cybercog/laravel-eloquent-flag

Usage

Usage examples described in Wiki

Changelog

Please see CHANGELOG for more information on what has changed recently.

Upgrading

Please see UPGRADING for detailed upgrade instructions.

Contributing

Please see CONTRIBUTING for details.

Testing

Run the tests with:

$ vendor/bin/phpunit

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributors

@antonkomarev
Anton Komarev
@zagreusinoz
zagreusinoz
@jonagoldman
Jona Goldman
@irazasyed
Irfaq Syed
@gpioto
gpioto
@rayronvictor
Rayron Victor

Eloquent Flag contributors list

Alternatives

Feel free to add more alternatives as Pull Request.

License

About CyberCog

CyberCog is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion.

CyberCog

laravel-eloquent-flag's People

Contributors

antonkomarev avatar zagreusinoz avatar vesper8 avatar irazasyed avatar jonagoldman avatar rayronvictor avatar gabrielpioto avatar

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.