cybercog / laravel-eloquent-flag
Laravel Eloquent boolean & timestamp flagged attributes behavior.
Fund package maintenance!
paypal.me/antonkomarev
Installs: 16 883
Dependents: 0
Suggesters: 0
Security: 0
Stars: 135
Watchers: 5
Forks: 20
Open Issues: 8
pkg:composer/cybercog/laravel-eloquent-flag
Requires
- php: ^8.0
- illuminate/database: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- phpunit/phpunit: ^9.6|^10.5|^11.5.3
This package is auto-updated.
Last update: 2025-10-22 13:57:40 UTC
README
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
- How it works
- Installation
- Usage
- Changelog
- Upgrading
- Contributing
- Testing
- Security
- Contributors
- Alternatives
- License
- About CyberCog
Features
- Designed to work with Laravel Eloquent models.
- Each model can have many flags.
- Each flag adds global query scopes to models.
- 2 logical groups of flags:
Classic,Inverse. - 2 types of flags:
Boolean,Timestamp. - Flag fields auto-casting to
bool&DateTime. - Following PHP Standard Recommendations:
- Covered with unit tests.
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:
Booleanflags are the common ones. Stored in database asBOOLEANorTINYINT(1)value.Timestampflags represented in database as nullableTIMESTAMPcolumn. Useful when you need to know when action was performed.
All flags separated on 2 logical groups:
Classicflags displays only entities withtrueortimestampflag value by default.Inverseflags displays only entities withfalseornullflag value by default.
Omitted entities could be retrieved by using special global scope methods, unique for each flag.
Example: If your
Articlemodel hasPublishedAtflag thenArticle::get()will return you only published records. When you need to get only unpublished records you could callArticle::onlyUnpublished()->get()andArticle::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 open@cybercog.su instead of using the issue tracker.
Contributors
Anton Komarev |
zagreusinoz |
Jona Goldman |
Irfaq Syed |
gpioto |
|---|---|---|---|---|
Rayron Victor |
Ugur Aydogdu |
Eloquent Flag contributors list
Alternatives
Feel free to add more alternatives as Pull Request.
License
Laravel Eloquent Flagpackage is open-sourced software licensed under the MIT license by Anton Komarev.Clockimage licensed under Creative Commons 3.0 by Rudez Studio.
About CyberCog
CyberCog is a Social Unity of enthusiasts. Research the best solutions in product & software development is our passion.

