PHPackages                             gksh/transistor - 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. gksh/transistor

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

gksh/transistor
===============

Laravel integration for gksh/bitmask

v1.0.1(5mo ago)32MITPHPPHP ^8.2CI passing

Since Jan 16Pushed 5mo agoCompare

[ Source](https://github.com/dotgksh/transistor)[ Packagist](https://packagist.org/packages/gksh/transistor)[ RSS](/packages/gksh-transistor/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (9)Versions (3)Used By (0)

 [![Transistor banner](https://camo.githubusercontent.com/640c34f837b1dd6260cbf9e787efb039b1a195f9f0e2541562f6b09dbaebcf3d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f676b73682532467472616e736973746f722e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d676b73682532467472616e736973746f72267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d426974776973652b6166666f7264616e6365732b696e2b4c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c696768746e696e672d626f6c74267769647468733d31303026686569676874733d313030)](https://camo.githubusercontent.com/640c34f837b1dd6260cbf9e787efb039b1a195f9f0e2541562f6b09dbaebcf3d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f676b73682532467472616e736973746f722e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d676b73682532467472616e736973746f72267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d426974776973652b6166666f7264616e6365732b696e2b4c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c696768746e696e672d626f6c74267769647468733d31303026686569676874733d313030)

Transistor
==========

[](#transistor)

Laravel integration for [gksh/bitmask](https://github.com/dotgksh/bitmask) - providing Eloquent casting, query scopes, validation, Blade directives, and migration macros for working with bitmask flags.

[![Latest Version on Packagist](https://camo.githubusercontent.com/cff7c1bceb0a94cf26a538bdecdfc8d1080badbdd4d1b25d4b4af62a1eb7ce75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676b73682f7472616e736973746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gksh/transistor)[![CI](https://github.com/dotgksh/transistor/actions/workflows/ci.yml/badge.svg)](https://github.com/dotgksh/transistor/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/e4f8deb92e912d75a1013c5a5152f2905f38a5c17d8f06777bf9cb6b51df63fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f676b73682f7472616e736973746f722e7376673f7374796c653d666c61742d737175617265)](https://github.com/dotgksh/transistor/blob/main/LICENSE)

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

[](#installation)

```
composer require gksh/transistor
```

The service provider is auto-discovered by Laravel.

Quick Start
-----------

[](#quick-start)

```
// 1. Generate a bitmask enum
php artisan make:bitmask-flags Permission

// 2. Add migration macro
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->bitmask('permissions');
});

// 3. Configure your model
use Gksh\Transistor\Casts\BitmaskCast;
use Gksh\Transistor\Concerns\HasBitmaskScopes;

class User extends Model
{
    use HasBitmaskScopes;

    protected function casts(): array
    {
        return [
            'permissions' => BitmaskCast::class,
        ];
    }
}

// 4. Use it
$user->permissions = $user->permissions
    ->set(Permission::Read)
    ->set(Permission::Write);

User::whereHasBitmaskFlag('permissions', Permission::Admin)->get();
```

Artisan Commands
----------------

[](#artisan-commands)

### make:bitmask-flags

[](#makebitmask-flags)

Generate a bitmask flags enum interactively:

```
php artisan make:bitmask-flags
php artisan make:bitmask-flags Permission
```

Creates an enum in `app/Enums` with bit-shifted values:

```
namespace App\Enums;

enum Permission: int
{
    case Read = 1  BitmaskCast::class,              // 32-bit (default)
        'settings' => BitmaskCast::class.':tiny',         // 8-bit (0-255)
        'features' => BitmaskCast::class.':small',        // 16-bit (0-65,535)
        'options' => BitmaskCast::class.':medium',        // 24-bit (0-16,777,215)
    ];
}
```

The cast returns a `Gksh\Bitmask\Bitmask` object with methods like `set()`, `unset()`, `toggle()`, `has()`, and `value()`.

Query Scopes
------------

[](#query-scopes)

Add the `HasBitmaskScopes` trait to your model:

```
use Gksh\Transistor\Concerns\HasBitmaskScopes;

class User extends Model
{
    use HasBitmaskScopes;
}
```

### Available Scopes

[](#available-scopes)

```
// Filter where flag IS set
User::whereHasBitmaskFlag('permissions', Permission::Read)->get();

// Filter where ALL flags are set
User::whereHasAllBitmaskFlags('permissions', [Permission::Read, Permission::Write])->get();

// Filter where ANY flag is set
User::whereHasAnyBitmaskFlag('permissions', [Permission::Write, Permission::Admin])->get();

// Filter where flag is NOT set
User::whereDoesntHaveBitmaskFlag('permissions', Permission::Admin)->get();

// Filter where NONE of the flags are set
User::whereDoesntHaveAnyBitmaskFlag('permissions', [Permission::Read, Permission::Write])->get();
```

Scopes can be chained:

```
User::whereHasBitmaskFlag('permissions', Permission::Read)
    ->whereDoesntHaveBitmaskFlag('permissions', Permission::Admin)
    ->get();
```

Migration Macros
----------------

[](#migration-macros)

Create bitmask columns with the appropriate integer size:

```
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->bitmask('permissions');       // unsigned integer (32-bit)
    $table->tinyBitmask('settings');      // unsigned tinyInteger (8-bit)
    $table->smallBitmask('features');     // unsigned smallInteger (16-bit)
    $table->mediumBitmask('options');     // unsigned mediumInteger (24-bit)
});
```

All macros set a default value of `0`.

Validation
----------

[](#validation)

### As a Rule Object

[](#as-a-rule-object)

```
use Gksh\Transistor\Rules\ValidBitmask;

$validated = $request->validate([
    'permissions' => ['required', new ValidBitmask()],
    'role_flags' => ['required', new ValidBitmask(Permission::class)],
]);
```

### As a String Rule

[](#as-a-string-rule)

```
$validated = $request->validate([
    'permissions' => 'required|bitmask',
    'role_flags' => 'required|bitmask:App\Enums\Permission',
]);
```

When an enum class is provided, the rule ensures the value doesn't exceed the maximum possible combination of all flags.

Blade Directives
----------------

[](#blade-directives)

```
@hasBitmaskFlag($user->permissions, Permission::Admin)
    Administrator
@endif

@hasAnyBitmaskFlag($user->permissions, [Permission::Write, Permission::Admin])
    Edit
@endif

@hasAllBitmaskFlags($user->permissions, [Permission::Read, Permission::Write])
    Full Access
@endif
```

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.x or 12.x

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance72

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~11 days

Total

2

Last Release

156d ago

### Community

Maintainers

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

---

Top Contributors

[![karkowg](https://avatars.githubusercontent.com/u/14905932?v=4)](https://github.com/karkowg "karkowg (12 commits)")

---

Tags

laraveleloquentflagscastbitmaskbitwise

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gksh-transistor/health.svg)

```
[![Health](https://phpackages.com/badges/gksh-transistor/health.svg)](https://phpackages.com/packages/gksh-transistor)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[watson/validating

Eloquent model validating trait.

9803.5M54](/packages/watson-validating)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.3M18](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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