### Install Attributes for Laravel with Composer and Artisan Source: https://github.com/roundly-consulting/attributes-for-laravel/blob/main/README.md Install the package via Composer, publish the migrations, and run the migrations. Requires PHP 8.4 and Laravel 12 or 13. If owner models use UUID/ULID keys, set ATTRIBUTES_KEY_TYPE before migrating. ```bash composer require roundly-consulting/attributes-for-laravel php artisan vendor:publish --tag="attributes-migrations" php artisan migrate ``` -------------------------------- ### Define, set, get, and query typed attributes Source: https://github.com/roundly-consulting/attributes-for-laravel/blob/main/README.md Shows how to define an attribute with validation rules, set and retrieve attributes, and use query scopes. Setting an invalid value throws InvalidAttributeValueException. The setMany example stores '5' as integer 5. ```php use RoundlyConsulting\Attributes\DataTransferObjects\AttributeDefinitionData; use RoundlyConsulting\Attributes\Enums\AttributeType; use RoundlyConsulting\Attributes\Facades\Attributes; Attributes::define(new AttributeDefinitionData( name: 'rating', type: AttributeType::Integer, rules: ['min:1', 'max:5'], )); Attributes::for($product)->set('color', 'red', meta: ['hex' => '#f00']); Attributes::for($product)->setMany(['rating' => '5', 'on_sale' => true]); // '5' is stored as 5 Attributes::for($product)->get('rating'); // 5 Attributes::for($product)->toKeyValue(); // ['color' => 'red', 'rating' => 5, 'on_sale' => true] Attributes::for($product)->set('rating', 9); // throws InvalidAttributeValueException Product::query()->whereAttribute('color', 'red')->whereAttributeBetween('rating', 4, 5)->get(); ``` -------------------------------- ### Add HasAttributes trait and contract to a model Source: https://github.com/roundly-consulting/attributes-for-laravel/blob/main/README.md Use the HasAttributes trait and implement the HasAttributes contract on any Eloquent model to enable dynamic attributes. The example shows a Product model. ```php use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Attributes\Contracts\HasAttributes as HasAttributesContract; use RoundlyConsulting\Attributes\Traits\HasAttributes; class Product extends Model implements HasAttributesContract { use HasAttributes; } ```