enumhancer icon indicating copy to clipboard operation
enumhancer copied to clipboard

[Laravel] Casting and Eloquent Builder for Bitmask

Open mostafaznv opened this issue 8 months ago • 0 comments

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 AsBitmask cast 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 InteractsWithBitmask trait providing whereBitmask and orWhereBitmask query 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 BitmaskPreferenceEnum as a fixture for testing bitmask enum functionality.
  • Adds CastsBitmaskEnumsModel for 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.~~

mostafaznv avatar Aug 09 '25 11:08 mostafaznv