The package ships three string-backed enums in RoundlyConsulting\Attributes\Enums:
| Enum | Cases (value) |
|---|---|
AttributeType | String_ (string), Integer (integer), Float_ (float), Boolean (boolean), Array_ (array), DateTime (datetime) |
UniqueScope | None (none), Owner (owner), Global_ (global) |
RevisionType | Attached (attached), Updated (updated), Detached (detached) |
Each uses the Helpers trait from enums-for-laravel, so on top of its own methods it gains values(), names(), labels(), options(), toOptions(), toArray(), collect(), count(), random(), readable()/label(), the case lookups (fromName(), tryFromName(), fromLabel(), tryFromLabel(), hasName(), hasValue()) and the fluent comparators (is(), isNot(), isIn(), isNotIn(), whenIs*()) — handy for a field-type select, an API schema or an admin screen:
use RoundlyConsulting\Attributes\Enums\AttributeType;
use RoundlyConsulting\Attributes\Enums\UniqueScope;
// Value => label map for a select input
AttributeType::toOptions(); // Collection: ['string' => 'String', 'integer' => 'Integer', ...]
AttributeType::toArray(); // the same map as a plain array
// Case lookups
AttributeType::fromName('Integer'); // AttributeType::Integer
AttributeType::hasValue('datetime'); // true
// Comparators and domain methods
AttributeType::DateTime->isIn([AttributeType::DateTime, AttributeType::Integer]); // true
UniqueScope::Global_->enforces(); // true — None is the only scope that does notThe validationRule() caveat
AttributeType keeps its own instance validationRule(), which returns the Laravel rule for a value of that type (string, integer, numeric, boolean, array, date). It intentionally shadows the trait’s static membership rule, so build the in: rule from the values when you need it. UniqueScope and RevisionType expose the trait’s static validationRule() normally:
AttributeType::Integer->validationRule(); // 'integer' — the rule for a value of this type
'in:'.AttributeType::values()->implode(','); // in:string,integer,float,boolean,array,datetime
UniqueScope::validationRule(); // 'in:none,owner,global'Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.