PHPackages                             cybercog/laravel-eloquent-flag - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. cybercog/laravel-eloquent-flag

ActiveLibrary[Database &amp; ORM](/categories/database)

cybercog/laravel-eloquent-flag
==============================

Laravel Eloquent boolean &amp; timestamp flagged attributes behavior.

6.3.0(2mo ago)13518.7k—10%20[8 issues](https://github.com/cybercog/laravel-eloquent-flag/issues)MITPHPPHP ^8.0CI passing

Since Sep 26Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/cybercog/laravel-eloquent-flag)[ Packagist](https://packagist.org/packages/cybercog/laravel-eloquent-flag)[ Docs](https://komarev.com/sources/laravel-eloquent-flag)[ Fund](https://paypal.me/antonkomarev)[ RSS](/packages/cybercog-laravel-eloquent-flag/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (40)Used By (0)

Laravel Eloquent Flag
=====================

[](#laravel-eloquent-flag)

[![cog-laravel-eloquent-flag](https://user-images.githubusercontent.com/1849174/53454214-7d38d680-3a37-11e9-953d-8daee98fb087.png)](https://user-images.githubusercontent.com/1849174/53454214-7d38d680-3a37-11e9-953d-8daee98fb087.png)

[![Discord](https://camo.githubusercontent.com/86e83e2f2ffe2f5caffed9d8886bb512bf42bf927dd8bb8e864d9e9983313ff7/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6f676f3d646973636f7264266c6162656c3d266d6573736167653d446973636f726426636f6c6f723d333633393366267374796c653d666c61742d737175617265)](https://discord.gg/rBqKTVT)[![Releases](https://camo.githubusercontent.com/7336c42f829e5b51fbe92836a34f1ea19f354008e56705612a9fd3ce84955776/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6379626572636f672f6c61726176656c2d656c6f7175656e742d666c61672e7376673f7374796c653d666c61742d737175617265)](https://github.com/cybercog/laravel-eloquent-flag/releases)[![Build](https://camo.githubusercontent.com/be456994d2a8fcc25ddaec954ad2a11871408a0b78d01472f6db20ef50df109a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6379626572636f672f6c61726176656c2d656c6f7175656e742d666c61672f74657374732e79616d6c3f7374796c653d666c61742d737175617265)](https://github.com/cybercog/laravel-eloquent-flag/actions/workflows/tests.yaml)[![StyleCI](https://camo.githubusercontent.com/d638b078a026066e13138180483a366e2e28af7ae1c6a1d68055c69ad04f4be0/68747470733a2f2f7374796c6563692e696f2f7265706f732f36393234353630372f736869656c64)](https://styleci.io/repos/69245607)[![Code Quality](https://camo.githubusercontent.com/d5f040394865815b1b37cc01fa6943d5e5eb4ea83fa365298e9a7a901b843986/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6379626572636f672f6c61726176656c2d656c6f7175656e742d666c61672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cybercog/laravel-eloquent-flag/?branch=master)[![License](https://camo.githubusercontent.com/dfdf2813bf26579059e5c4e4f89351bf1fcc3bacd65a55827b75ab8ad44863b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6379626572636f672f6c61726176656c2d656c6f7175656e742d666c61672e7376673f7374796c653d666c61742d737175617265)](https://github.com/cybercog/laravel-eloquent-flag/blob/master/LICENSE)

Introduction
------------

[](#introduction)

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

Contents
--------

[](#contents)

- [Features](#features)
- [Available flags list](#available-flags-list)
- [How it works](#how-it-works)
- [Installation](#installation)
- [Usage](#usage)
- [Changelog](#changelog)
- [Upgrading](#upgrading)
- [Contributing](#contributing)
- [Testing](#testing)
- [Security](#security)
- [Contributors](#contributors)
- [Alternatives](#alternatives)
- [License](#license)
- [About CyberCog](#about-cybercog)

Features
--------

[](#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` &amp; `DateTime`.
- Following PHP Standard Recommendations:
    - [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/).
    - [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/).
    - [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/).
- Covered with unit tests.

Available flags list
--------------------

[](#available-flags-list)

Trait nameLogicDatabase columnFlag typeConflict`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
------------

[](#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
------------

[](#installation)

Pull in the package through Composer.

```
composer require cybercog/laravel-eloquent-flag
```

Usage
-----

[](#usage)

[Usage examples described in Wiki](https://github.com/cybercog/laravel-eloquent-flag/wiki/usage)

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Upgrading
---------

[](#upgrading)

Please see [UPGRADING](UPGRADING.md) for detailed upgrade instructions.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Testing
-------

[](#testing)

Run the tests with:

```
vendor/bin/phpunit
```

Security
--------

[](#security)

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

Contributors
------------

[](#contributors)

[![@antonkomarev](https://avatars.githubusercontent.com/u/1849174?s=110)
Anton Komarev](https://github.com/antonkomarev)[![@zagreusinoz](https://avatars.githubusercontent.com/u/16147285?s=110)
zagreusinoz](https://github.com/zagreusinoz)[![@jonagoldman](https://avatars.githubusercontent.com/u/1297559?s=110)
Jona Goldman](https://github.com/jonagoldman)[![@irazasyed](https://avatars.githubusercontent.com/u/1915268?s=110)
Irfaq Syed](https://github.com/irazasyed)[![@gpioto](https://avatars.githubusercontent.com/u/7549089?s=110)
gpioto](https://github.com/gpioto)[![@rayronvictor](https://avatars.githubusercontent.com/u/1683922?s=110)
Rayron Victor](https://github.com/rayronvictor)[![@jnbn](https://avatars.githubusercontent.com/u/112425?s=110)
Ugur Aydogdu](https://github.com/jnbn)[Eloquent Flag contributors list](../../contributors)

Alternatives
------------

[](#alternatives)

*Feel free to add more alternatives as Pull Request.*

License
-------

[](#license)

- `Laravel Eloquent Flag` package is open-sourced software licensed under the [MIT license](LICENSE) by [Anton Komarev](https://komarev.com).
- `Clock` image licensed under [Creative Commons 3.0](https://creativecommons.org/licenses/by/3.0/us/) by Rudez Studio.

About CyberCog
--------------

[](#about-cybercog)

[CyberCog](https://cybercog.su) is a Social Unity of enthusiasts. Research the best solutions in product &amp; software development is our passion.

- [Follow us on Twitter](https://twitter.com/cybercog)
- [Read our articles on Medium](https://medium.com/cybercog)

[![CyberCog](https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png)](https://cybercog.su)

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance84

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 89.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~95 days

Recently: every ~275 days

Total

37

Last Release

78d ago

Major Versions

1.5.0 → 2.0.02017-01-04

2.1.0 → 3.0.02017-01-06

3.13.1 → 4.0.02018-09-09

4.0.0 → 5.0.02019-03-18

5.4.0 → 6.0.02023-02-24

PHP version history (5 changes)1.0.0PHP ^5.6|^7.0

5.0.0PHP ^7.1.3

5.3.0PHP ^7.1.3|8.0

5.3.1PHP ^7.1.3|^8.0

6.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3fddc40462126bbc119e373ed6a3f942a90a400f30c076c447c0625b841c4ef?d=identicon)[antonkomarev](/maintainers/antonkomarev)

---

Top Contributors

[![antonkomarev](https://avatars.githubusercontent.com/u/1849174?v=4)](https://github.com/antonkomarev "antonkomarev (92 commits)")[![zagreusinoz](https://avatars.githubusercontent.com/u/16147285?v=4)](https://github.com/zagreusinoz "zagreusinoz (2 commits)")[![maherelgamil](https://avatars.githubusercontent.com/u/6294478?v=4)](https://github.com/maherelgamil "maherelgamil (2 commits)")[![jnbn](https://avatars.githubusercontent.com/u/112425?v=4)](https://github.com/jnbn "jnbn (1 commits)")[![jonagoldman](https://avatars.githubusercontent.com/u/1297559?v=4)](https://github.com/jonagoldman "jonagoldman (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![gabrielpioto](https://avatars.githubusercontent.com/u/76054805?v=4)](https://github.com/gabrielpioto "gabrielpioto (1 commits)")[![rayronvictor](https://avatars.githubusercontent.com/u/1683922?v=4)](https://github.com/rayronvictor "rayronvictor (1 commits)")[![vesper8](https://avatars.githubusercontent.com/u/816028?v=4)](https://github.com/vesper8 "vesper8 (1 commits)")[![irazasyed](https://avatars.githubusercontent.com/u/1915268?v=4)](https://github.com/irazasyed "irazasyed (1 commits)")

---

Tags

acceptedactiveapprovebooleancogeloquentexpiredflagkeptlaravelopenedpackagephppublishedscopestatestatustimestamptraitverifiedlaraveltraitstateflagscopesstatusactivetogglecogtimestampcybercogpublishedexpiredexpirybooleanverifiedpersistedclosedacceptedkeptunacceptedactivateddeactivatedunkeptunpublishedunverifiedapprovedunapprovedinactiveopenedended

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cybercog-laravel-eloquent-flag/health.svg)

```
[![Health](https://phpackages.com/badges/cybercog-laravel-eloquent-flag/health.svg)](https://phpackages.com/packages/cybercog-laravel-eloquent-flag)
```

###  Alternatives

[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[cybercog/laravel-nova-ban

A Laravel Nova banning functionality for your application.

40199.8k](/packages/cybercog-laravel-nova-ban)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
