Eloquent boolean & timestamp flagged attributes behavior. Enhance eloquent models with commonly used state flags like Active
, Published
, Approved
and others in a minutes!
- Features
- Available flags list
- How it works
- Installation
- Usage
- Change log
- Upgrading
- Contributing
- Testing
- Security
- Credits
- Alternatives
- License
- About CyberCog
- Designed to work with Laravel Eloquent models.
- Each model can has as many flags as required.
- Each flag adds global query scopes to models.
- 2 logical groups of flags:
Classic
,Inverse
. - 2 types of flags:
Boolean
,Timestamp
. - Following PHP Standard Recommendations:
- Covered with unit tests.
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 |
HasEndededFlag |
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.
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 asBOOLEAN
orTINYINT(1)
value.Timestamp
flags represented in database as nullableTIMESTAMP
column. Useful when you need to know when action was performed.
All flags separated on 2 logical groups:
Classic
flags displays only entities withtrue
ortimestamp
flag value.Inverse
flags displays only entities withfalse
ornull
flag value.
Omitted entities could be retrieved by using special global scope methods, unique for each flag.
First, pull in the package through Composer.
composer require cybercog/laravel-eloquent-flag
And then include the service provider within app/config/app.php
.
// Service provider not using yet. This step not mandatory. Will be used to boot console commands in future.
'providers' => [
Cog\Flag\Providers\FlagServiceProvider::class,
];
Usage examples described in Wiki
Please see CHANGELOG for more information on what has changed recently.
Please see UPGRADING for detailed upgrade instructions.
Please see CONTRIBUTING for details.
Run the tests with:
vendor/bin/phpunit
If you discover any security related issues, please email open@cybercog.su instead of using the issue tracker.
Anton Komarev |
zagreusinoz |
---|
Eloquent Flag contributors list
Not found.
Feel free to add more alternatives as Pull Request.
Laravel Eloquent Flag
package is open-sourced software licensed under the MIT license.Check Mark
image licensed under Creative Commons 3.0 by Kimmi Studio.Clock Check
image licensed under Creative Commons 3.0 by Harsha Rai.
CyberCog is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion.