Overview
TheFormatsValues trait provides methods for formatting values for display in form components and checking value types. It includes support for PHP Enums, Eloquent models, booleans, and collections.
Namespace: Javaabu\Forms\Support
Trait Definition
Dependencies
This trait works with:- PHP 8.1+
BackedEnum Illuminate\Database\Eloquent\ModelIlluminate\Support\Collection
Methods
getEnumLabel
string - The enum label, or empty string if not an enum
Label Resolution:
- If enum has
getLabel()method, uses that - Otherwise uses the enum’s
nameproperty - Returns empty string if value is not an enum
isStatusEnum
getColor() method).
Returns: bool - True if value is a BackedEnum with getColor() method
Example:
isAdminModel
bool - True if value is a Model with getAdminLinkAttribute() method
Example:
checkIfIsAdminModel
The value to check.
bool - True if value is a Model with getAdminLinkAttribute() method
Example:
isAdminModelCollection
bool - True if value is a Collection where all items are admin models
Validation:
- Value must be a Collection
- All items in collection must be admin models
- Returns false if any item is not an admin model
formatValue
mixed - The formatted value
Formatting Rules:
- BackedEnum: Returns enum label via
getEnumLabel() - Boolean: Returns translated “Yes” or “No”
- Empty (non-numeric): Returns translated “Blank”
- Other: Returns value as-is