• Stars
    star
    133
  • Rank 271,791 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 8 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Laravel Eloquent boolean & timestamp flagged attributes behavior.

Laravel Eloquent Flag

cog-laravel-eloquent-flag

Discord Releases Build 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
@jnbn
Ugur Aydogdu

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

More Repositories

1

laravel-love

Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?
PHP
1,048
star
2

laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.
PHP
979
star
3

laravel-paket

Composer GUI. Manage Laravel dependencies from web interface without switching to command line!
PHP
174
star
4

laravel-optimus

Transform your internal id's to obfuscated integers based on Knuth's integer hash. Laravel wrapper for the Optimus Library by Jens Segers with multiple connections support.
PHP
171
star
5

laravel-likeable

Rate Eloquent models with Likes and Dislikes in Laravel. Development moved to Laravel Love package!
PHP
93
star
6

laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.
PHP
83
star
7

laravel-whoops-editor

Laravel Whoops Editor helps to open your code editor from exception stack trace.
PHP
83
star
8

laravel-nova-ban

Laravel Nova Ban simplify blocking and banning Eloquent models.
PHP
41
star
9

youtrack-rest-php

JetBrains YouTrack REST API PHP Client
PHP
35
star
10

laravel-clickhouse

Laravel ClickHouse adds CH client integration, generation & execution of ClickHouse database migrations to the Laravel application.
PHP
22
star
11

laravel-youtrack-sdk

Laravel wrapper for the YouTrack PHP Software Development Kit provides set of tools to interact with JetBrains YouTrack.
PHP
18
star
12

laravel-sense

Application profiling. That makes sense.
PHP
14
star
13

yii2-google-analytics

Google Analytics Universal tracking widget.
PHP
14
star
14

youtrack-php-sdk

YouTrack PHP Software Development Kit provides set of tools to interact with JetBrains YouTrack.
PHP
9
star
15

laravel-notification-channel-rocket-chat

Project moved to https://github.com/laravel-notification-channels/rocket-chat
PHP
8
star
16

php-contracts-weblog

Сontracts for the framework agnostic Blog development.
PHP
6
star
17

telegram-devpoker-bot

Planning Poker (Scrum Poker) for Agile software development teams. The bot allows you to introduce a consensus-based, gamified technique of task estimating into Telegram group chats.
Python
4
star
18

php-pushwoosh

A PHP Library to easily send PUSH notifications with the Pushwoosh REST Web Services.
PHP
4
star
19

laravel-service-provider

(UNMAINTAINED) Base Laravel service provider mockup with utility functions to speedup packages deployment.
PHP
4
star
20

php-db-locker

PHP application-level database locking mechanisms to implement concurrency control patterns.
PHP
3
star
21

orcish-translator

Orkish language translator. Usable for Warhammer settings. Discover the power of Waaagh!!!
Perl
3
star
22

yii2-twittable

Autoposting/deleting tweets
PHP
2
star
23

clip

Cloud clipboard. Qt client for Linux/Windows and Web Yii2 application
PHP
1
star
24

git-timetracker

PHP and git based time tracking.
JavaScript
1
star
25

laravel-data

Laravel Data Transfer Object
1
star
26

php-hydra

1
star
27

php-safecrow-sdk

PHP Safecrow REST API SDK
PHP
1
star