PHPackages                             aw-studio/laravel-bitflags - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. aw-studio/laravel-bitflags

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aw-studio/laravel-bitflags
==========================

v0.1(4y ago)01.4k1MITPHPPHP ^8.0

Since Jul 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/aw-studio/laravel-bitflags)[ Packagist](https://packagist.org/packages/aw-studio/laravel-bitflags)[ RSS](/packages/aw-studio-laravel-bitflags/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Laravel Bitflags
================

[](#laravel-bitflags)

Store and receive bitflags from a single database column.

Installation
------------

[](#installation)

```
composer require aw-studio/bitflags
```

Usage
-----

[](#usage)

Imagine you want to store multiple status flags in a single `status(int)` column of your `Email` model. This can be achieved using bitwise operations to create a representative `bitmask`. In order to enable bitwise operations bitflags `MUST` all be powers of two (1,2,4,8,16 …). You should also make shure to properly cast the column as `Bitflags::class`.

```
class Email extends Model
{
    // Email status flags, all powers of 2
    public const SENT = 1;
    public const RECEIVED = 2;
    public const SEEN = 4;
    public const READ = 8;

    protected $fillable = ['status'];

    public $casts = [
        'status' => Bitflags::class
    ];
}
```

### Adding a flag to a bitmask

[](#adding-a-flag-to-a-bitmask)

Adding a `bitflag` to a bitmask can be achieved using the `addBitflag()` helper:

```
public function markRead()
{
    $this->update([
        'status' => addBitflag(self::READ, $this->status)
    ]);
}
```

You can also add multiple flags at once:

```
$this->update([
    'status' => addBitflag([self::READ, self::SEEN], $this->status)
]);
```

### Removing a flag from a bitmask

[](#removing-a-flag-from-a-bitmask)

Removing a `bitflag` from a bitmask can be achieved using the `removeBitflag()` helper:

```
public function markUnread()
{
    $this->update([
        'status' => removeBitflag(self::READ, $this->status)
    ]);
}
```

Remove multiple flags at once:

```
$this->update([
    'status' => removeBitflag([self::READ, self::SEEN], $this->status)
]);
```

### Query bitflags

[](#query-bitflags)

To check if bitflags are included in a bitmask you may use the following query methods:

```
public function scopeRead($query)
{
    return $this->whereBitflag('status', self::READ);
}
public function scopeUnread($query)
{
    return $this->whereBitflagNot('status', self::READ);
}
public function scopeSeenOrRead($query)
{
    return $this->whereBitflagIn('status', [self::READ, self::SEEN]);
}
public function scopeSeenAndRead($query)
{
    return $this->whereBitflags('status', [self::READ, self::SEEN]);
}
```

Accessors
---------

[](#accessors)

In order to get single flag attributes you can prepare accessors as follows:

```
protected $appends = ['read'];

public function getReadAttribute()
{
    return inBitmask(self::READ, $this->status);
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% 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

Unknown

Total

1

Last Release

1755d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b2d65d58480dd7fdbf4f4593158cbd0634550ee9210c49957cc48c8a8ccaef6?d=identicon)[jannescb](/maintainers/jannescb)

---

Top Contributors

[![jannescb](https://avatars.githubusercontent.com/u/17292622?v=4)](https://github.com/jannescb "jannescb (13 commits)")[![cbl](https://avatars.githubusercontent.com/u/29352871?v=4)](https://github.com/cbl "cbl (1 commits)")[![lpheller](https://avatars.githubusercontent.com/u/36259611?v=4)](https://github.com/lpheller "lpheller (1 commits)")

---

Tags

bitflagbitflagsbitmaskbitmaskingbitwiselaravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aw-studio-laravel-bitflags/health.svg)

```
[![Health](https://phpackages.com/badges/aw-studio-laravel-bitflags/health.svg)](https://phpackages.com/packages/aw-studio-laravel-bitflags)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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