Installation
Require the package. The service provider is auto-discovered — no manual registration:
composer require roundly-consulting/attributes-for-laravelPublish the migrations, then run them:
php artisan vendor:publish --tag="attributes-migrations"
php artisan migratePublish-only migrations
The package never loads its migrations for you. Publishing copies three timestamped files into your app’s database/migrations, where you own them and can adjust the schema before migrating: the attributes table, the attribute_revisions audit table and update_attribute_revisions_add_actor, which adds the nullable actor columns that record who made each change (sorted after the two create migrations).
If your owner models use UUID or ULID keys, publish the config and set key_type before you migrate — the owner columns are typed when the migrations run (see Database schema & model). The actor columns take their own actor_key_type, for when your users use other keys than your owner models.
Optionally publish the config file:
php artisan vendor:publish --tag="attributes-config"The only publish tags the package exposes are attributes-migrations and attributes-config.
Upgrading to 2.2
2.2.0 adds 'unique' => 'scope' — unique values per team or tenant — on the existing unique_hash index, so there is no migration. A definition with a unique_scope key but a unique value other than scope now throws instead of being ignored. The next major plans to rename 'unique' => 'owner' to 'owner_type': it has always meant one pool per owner type, which in a multi-tenant app spans every tenant.
Upgrading to 2.1
2.1.0 adds one additive migration, for the revisions’ actor columns, and now requires illuminate/http (for the API resources). Publish the migrations again and migrate:
# 2.1.0 adds one migration — the revisions' actor columns
php artisan vendor:publish --tag="attributes-migrations"
php artisan migrateYour published create migrations are recognised by their content and left where they are; only update_attribute_revisions_add_actor is added, with a newer timestamp. If you edited a published create migration, the publisher no longer recognises it and adds a second copy — delete that one before you migrate. Everything new is opt-in: actor recording (history.actor.enabled) and whole-set validation (validation.whole_set) stay off until you turn them on, so nothing changes on upgrade. Run the migration before you enable actor recording — the next major plans to turn it on by default.
Next steps
- Add the HasAttributes trait and contract to a model.
- Attach your first typed attribute with Attributes::for($model)->set().
- Register definitions when you want validation, defaults or constraints.
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.