enumhancer
enumhancer copied to clipboard
[Laravel] Casting and Eloquent Builder for Bitmask
This pull request introduces comprehensive support for bitmask-based enums in Laravel Eloquent models, including a new attribute cast (AsBitmask), expressive query scopes for bitmask columns, and thorough documentation and test coverage. The changes make it much easier to store, retrieve, and query sets of enum values efficiently in a single database column.
Laravel Bitmask Enum Support
- New Eloquent Attribute Cast:
- [x] Adds
AsBitmaskcast to allow storing and retrieving multiple enum values as a single integer column in Eloquent models. Handles conversion from arrays, strings, single enum cases, and Bitmask objects, and supports serialization. - [x] Documentation added for using bitmask enums with Eloquent attribute casting, including usage examples and configuration. (
docs/casting.md,docs/bitmasks.md)
- Bitmask Query Scopes:
- [x] Introduces
InteractsWithBitmasktrait providingwhereBitmaskandorWhereBitmaskquery scopes for expressive filtering of bitmask columns. - [x] Documentation for these query scopes and how to use them in Eloquent models. (
docs/laravel.eloquent.md)
Testing and Fixtures
- Adds
BitmaskPreferenceEnumas a fixture for testing bitmask enum functionality. - Adds
CastsBitmaskEnumsModelfor testing Eloquent integration with bitmask enums.
~~CI Workflow Enhancements Expands GitHub Actions test matrix to cover multiple PHP and Laravel versions, and adjusts Composer install steps accordingly.~~