Download the PHP package cmandersen/bitwise without Composer
On this page you can find all versions of the php package cmandersen/bitwise. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cmandersen/bitwise
More information about cmandersen/bitwise
Files in cmandersen/bitwise
Package bitwise
Short Description A bitwise operator package for making it easier to use bitwise columns in Eloquent models
License MIT
Informations about the package bitwise
Laravel Bitwise Package
A Laravel package that makes it easy to work with bitwise flags in Eloquent models. Store multiple boolean flags efficiently in a single integer database column with natural query syntax.
Requirements
- PHP 8.0 or higher
- Laravel 9.x, 10.x, 11.x, or 12.x
Installation
Install the package via Composer:
The package will automatically register itself via Laravel's package discovery.
Setup Your Database
Create your database column as an unsigned integer:
Cast Your Model Attributes
Add bitwise casting to your Eloquent model attributes:
Working with Flags
Once cast, your attribute becomes a BitwiseCollection with many helpful methods:
Querying Models by Flags
The package automatically adds powerful query methods to all your models. No traits or additional setup required!
Basic Queries
Combining with Other Conditions
Complete Query Reference
All methods support OR variations (prefix with or):
whereBitwise($column, $flags)- Has specified flagswhereHasBitwise($column, $flags)- Alias for whereBitwisewhereHasAnyBitwise($column, $flags)- Has any of the flagswhereDoesntHaveBitwise($column, $flags)- Doesn't have flagswhereBitwiseEquals($column, $flags)- Has exactly these flagswhereInBitwise($column, $values)- Bitwise equivalent of whereInwhereNotInBitwise($column, $values)- Bitwise equivalent of whereNotIn
Array-like Access
BitwiseCollection implements ArrayAccess, so you can use array syntax:
Setting Flags During Creation/Update
You can set flags in several ways:
Advanced Usage
For more advanced use cases, you can work with individual flags and utilities:
Manual Flag Generation
Working with Individual Flags
Methods Reference
BitwiseCollection Methods
| Method | Description | Returns |
|---|---|---|
has(...$flags) |
Check if all specified flags are set | bool |
hasAny(...$flags) |
Check if any specified flags are set | bool |
add(...$flags) |
Add flags (returns new instance) | BitwiseCollection |
remove(...$flags) |
Remove flags (returns new instance) | BitwiseCollection |
toggle(...$flags) |
Toggle flags (returns new instance) | BitwiseCollection |
only(...$flags) |
Keep only specified flags | BitwiseCollection |
except(...$flags) |
Remove specified flags (alias for remove) | BitwiseCollection |
clear() |
Remove all flags | BitwiseCollection |
all() |
Set all available flags | BitwiseCollection |
getValue() |
Get integer value | int |
getFlags() |
Get array of BitwiseFlag objects | array |
getFlagNames() |
Get array of active flag names | array |
isEmpty() |
Check if no flags are set | bool |
isNotEmpty() |
Check if any flags are set | bool |
toArray() |
Get array of active flag names | array |
count() |
Count active flags | int |
BitwiseFlag Methods
| Method | Description | Returns |
|---|---|---|
is($flag) |
Check if this flag matches another | bool |
hasValue($value) |
Check if flag has specific value | bool |
isPowerOfTwo() |
Check if value is power of 2 | bool |
combine(...$flags) |
Combine with other flags | int |
isSetIn($value) |
Check if flag is set in value | bool |
setBit($value) |
Set this flag in value | int |
unsetBit($value) |
Unset this flag in value | int |
toggleBit($value) |
Toggle this flag in value | int |
License
This package is open-sourced software licensed under the MIT license.
All versions of bitwise with dependencies
illuminate/contracts Version ^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0