{"id":43919295,"url":"https://github.com/aw-studio/laravel-bitflags","last_synced_at":"2026-02-06T22:07:17.904Z","repository":{"id":48367444,"uuid":"389767665","full_name":"aw-studio/laravel-bitflags","owner":"aw-studio","description":"Store bitmask in database, cast bitmask for auto de-/encoding bitflags.","archived":false,"fork":false,"pushed_at":"2021-07-30T08:32:51.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-26T19:40:14.754Z","etag":null,"topics":["bitflag","bitflags","bitmask","bitmasking","bitwise","laravel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aw-studio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-26T21:03:54.000Z","updated_at":"2021-07-29T16:51:10.000Z","dependencies_parsed_at":"2022-08-29T14:43:25.112Z","dependency_job_id":null,"html_url":"https://github.com/aw-studio/laravel-bitflags","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/aw-studio/laravel-bitflags","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aw-studio%2Flaravel-bitflags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aw-studio%2Flaravel-bitflags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aw-studio%2Flaravel-bitflags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aw-studio%2Flaravel-bitflags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aw-studio","download_url":"https://codeload.github.com/aw-studio/laravel-bitflags/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aw-studio%2Flaravel-bitflags/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29178619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T20:14:21.878Z","status":"ssl_error","status_checked_at":"2026-02-06T20:14:21.443Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitflag","bitflags","bitmask","bitmasking","bitwise","laravel"],"created_at":"2026-02-06T22:07:16.452Z","updated_at":"2026-02-06T22:07:17.892Z","avatar_url":"https://github.com/aw-studio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Bitflags\n\nStore and receive bitflags from a single database column.\n\n## Installation\n\n```bash\ncomposer require aw-studio/bitflags\n```\n\n## Usage\n\nImagine you want to store multiple status flags in a single `status(int)` column of your `Email` model.\nThis can be achieved using bitwise operations to create a representative `bitmask`.\nIn order to enable bitwise operations bitflags `MUST` all be powers of two (1,2,4,8,16 …).\nYou should also make shure to properly cast the column as `Bitflags::class`.\n\n```php\nclass Email extends Model\n{\n    // Email status flags, all powers of 2\n    public const SENT = 1;\n    public const RECEIVED = 2;\n    public const SEEN = 4;\n    public const READ = 8;\n\n    protected $fillable = ['status'];\n\n    public $casts = [\n        'status' =\u003e Bitflags::class\n    ];\n}\n```\n\n### Adding a flag to a bitmask\n\nAdding a `bitflag` to a bitmask can be achieved using the `addBitflag()` helper:\n\n```php\npublic function markRead()\n{\n    $this-\u003eupdate([\n        'status' =\u003e addBitflag(self::READ, $this-\u003estatus)\n    ]);\n}\n```\n\nYou can also add multiple flags at once:\n\n```php\n$this-\u003eupdate([\n    'status' =\u003e addBitflag([self::READ, self::SEEN], $this-\u003estatus)\n]);\n```\n\n### Removing a flag from a bitmask\n\nRemoving a `bitflag` from a bitmask can be achieved using the `removeBitflag()` helper:\n\n```php\npublic function markUnread()\n{\n    $this-\u003eupdate([\n        'status' =\u003e removeBitflag(self::READ, $this-\u003estatus)\n    ]);\n}\n```\n\nRemove multiple flags at once:\n\n```php\n$this-\u003eupdate([\n    'status' =\u003e removeBitflag([self::READ, self::SEEN], $this-\u003estatus)\n]);\n```\n\n### Query bitflags\n\nTo check if bitflags are included in a bitmask you may use the following query methods:\n\n```php\npublic function scopeRead($query)\n{\n    return $this-\u003ewhereBitflag('status', self::READ);\n}\npublic function scopeUnread($query)\n{\n    return $this-\u003ewhereBitflagNot('status', self::READ);\n}\npublic function scopeSeenOrRead($query)\n{\n    return $this-\u003ewhereBitflagIn('status', [self::READ, self::SEEN]);\n}\npublic function scopeSeenAndRead($query)\n{\n    return $this-\u003ewhereBitflags('status', [self::READ, self::SEEN]);\n}\n```\n\n## Accessors\n\nIn order to get single flag attributes you can prepare accessors as follows:\n\n```php\nprotected $appends = ['read'];\n\npublic function getReadAttribute()\n{\n    return inBitmask(self::READ, $this-\u003estatus);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faw-studio%2Flaravel-bitflags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faw-studio%2Flaravel-bitflags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faw-studio%2Flaravel-bitflags/lists"}