Laravel Schemaless Attributes
Add NoSQL-style schemaless attributes to Eloquent models, stored in a single JSON column.
Repository Health
Technical Analysis
Laravel Schemaless Attributes brings a bit of NoSQL flexibility to Eloquent. It provides a trait and a cast that let you store arbitrary key-value data in a single JSON column on any model, without adding migrations for every new field.
You interact with the data as if it were normal model properties — object access, array access, dot notation, and defaults all work — and the package adds query scopes so you can filter records by their schemaless values directly in the database.
What You Get
- A trait/cast that turns a JSON column into a flexible, schemaless attribute bag on any Eloquent model
- Object, array, and dot-notation access to nested values with default fallbacks
- Query scopes to filter models by their schemaless attribute values
- A migration helper for adding the backing JSON column
Common Use Cases
- Storing optional or variable metadata on a model without a migration per field
- Adding user preferences, settings, or feature flags to an existing model
- Prototyping evolving data shapes where the schema is not yet settled
Under The Hood
Architecture — The core is SchemalessAttributes, an ArrayAccess object that wraps a model’s JSON column and mediates get/set with dot-notation support. SchemalessAttributesTrait (and the newer HasSchemalessAttributes concern) registers the accessor and the Casts/SchemalessAttributes cast on the model, while SchemalessAttributesServiceProvider wires the package into Laravel. Query scopes translate attribute lookups into JSON path queries against the database column.
Tech Stack — PHP built on Laravel’s Eloquent (illuminate/*) using its JSON column support and custom casts. Tests use Pest with an in-memory test model.
Code Quality — A compact, focused codebase following Spatie’s conventions, with a solid Pest test suite covering both the legacy trait and the newer concern, datasets, and cast behavior. CI runs the tests across supported Laravel versions.
API Design — Excellent ergonomics: after adding one column and the trait, developers use $model->extra_attributes->key, array access, or dot notation exactly as they’d expect, and the query scopes make filtering on schemaless data feel native to Eloquent.