DEV.co
Open-Source Databases · spatie

laravel-schemaless-attributes

Laravel Schemaless Attributes is a PHP package that lets you store arbitrary JSON data in a single database column on Eloquent models, combining relational database structure with flexible NoSQL-like attribute storage. It provides convenient object and array access patterns, dot notation queries, and built-in Eloquent scopes for filtering by schemaless values.

Source: GitHub — github.com/spatie/laravel-schemaless-attributes
1.1k
GitHub stars
53
Forks
PHP
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryspatie/laravel-schemaless-attributes
Ownerspatie
Primary languagePHP
LicenseMIT — OSI-approved
Stars1.1k
Forks53
Open issues0
Latest release2.6.0 (2026-02-21)
Last updated2026-06-02
Sourcehttps://github.com/spatie/laravel-schemaless-attributes

What laravel-schemaless-attributes is

A Laravel/Eloquent trait and custom cast that wraps JSON columns (MySQL 5.7+, PostgreSQL) to provide fluent object/array interfaces for reading and writing arbitrary nested attributes. Includes query scopes for filtering models by schemaless attribute values using JSON operators, and supports multiple schemaless columns per model.

Quickstart

Get the laravel-schemaless-attributes source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/spatie/laravel-schemaless-attributes.gitcd laravel-schemaless-attributes# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Product variant metadata

Store product-specific attributes (size, color, material, warranty terms) without schema migration for each new field, enabling rapid product catalog expansion.

User preferences and settings

Persist user-configurable options (UI theme, notification rules, privacy settings) as flexible JSON without creating normalized preference tables.

Event or audit metadata

Capture context-specific data alongside event records (request headers, IP, user agent, custom parameters) without predefined schema.

Implementation considerations

  • Requires explicit database migration using `schemalessAttributes()` blueprint method to add JSON column; not automatic.
  • Model setup requires both a custom cast declaration and scope method per schemaless column; boilerplate can be reduced via reusable trait.
  • JSON queries (via scopes) rely on database JSON operators; performance depends on database indexing strategy and query complexity.
  • Data is not validated at the cast layer; implement application validation to ensure data quality before save.
  • Nested dot notation is supported in `get()`/`set()` but not all database JSON implementations handle deep nesting equally.

When to avoid it — and what to weigh

  • Highly queryable complex data — If you need frequent, complex queries across multiple nested attributes with aggregations, normalization to proper tables is more maintainable and performant.
  • Multi-database support with non-JSON engines — Project must run on SQLite 3.38 without JSON support or legacy databases without JSON column types; this package requires JSON column support.
  • Strict data validation at database level — If compliance, auditing, or strict schema enforcement is mandatory, schemaless attributes bypass database schema constraints and should be complemented with application-level validation.
  • Team unfamiliar with JSON operators — Teams new to JSON query syntax in SQL may find maintenance and debugging of scope queries more difficult than normalized schemas.

License & commercial use

Licensed under MIT (Massachusetts Institute of Technology License), a permissive open-source license allowing unrestricted use, modification, and distribution with minimal conditions.

MIT license permits commercial use without restriction. However, review the project's security policy and conduct own security audit before deploying in production environments. Warranty and support are not provided by the license; rely on community support or commercial Laravel support vendors.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Schemaless attributes bypass database schema validation; implement application-level input validation and sanitization before storing user data. JSON injection is theoretically possible if data is not sanitized; use parameterized queries (cast handles this). No known CVEs in recent releases. Review security policy link in README for vulnerability reporting.

Alternatives to consider

jsonable/laravel-mutators or native Laravel accessors/mutators

Lighter-weight for simple JSON storage; no trait required, but less convenient for querying and lacks built-in scopes.

Doctrine DBAL or Eloquent attribute casts with custom logic

More control over serialization; useful if you need complex validation or polymorphic behavior, but requires more boilerplate.

Document-oriented databases (MongoDB, Firestore)

If schema flexibility is the primary requirement, a native NoSQL store eliminates schemaless workarounds; trade-off: abandons relational consistency and requires different query language.

Software development agency

Build on laravel-schemaless-attributes with DEV.co software developers

Our Laravel and API development teams can help you architect schemaless storage for rapid feature iteration while maintaining query performance and data integrity.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

laravel-schemaless-attributes FAQ

Can I query schemaless attributes with complex conditions (e.g., range, regex)?
The `withExtraAttributes()` scope supports custom operators (e.g., `LIKE`, `>`, `<`); exact capability depends on your database's JSON query support. MySQL and PostgreSQL both support rich JSON operators. Test edge cases in your target database.
Will schemaless attributes work with Eloquent relationships or eager loading?
Yes; schemaless attributes are cast on model instances. Use standard Eloquent eager loading (`with()`) and relationship queries; schemaless data is available on loaded models.
Is there a performance penalty compared to fixed columns?
Minimal for reads/writes; schemaless columns are standard JSON fields. Querying via scopes may be slower than indexed fixed columns if done frequently; consider indexing JSON paths in your database if queries are critical.
Can I use this with API resources or responses?
Yes; the cast serializes to JSON on model serialization (e.g., `toJson()`). Ensure your API resource maps the schemaless attribute correctly if using custom resource classes.

Work with a software development agency

Adopting laravel-schemaless-attributes is usually one piece of a larger software development effort. As a software development agency, DEV.co provides software development services and web development expertise — pairing senior software developers and web developers with your team to design, build, and operate open-source databases software in production.

Need help integrating flexible data storage into your Laravel app?

Our Laravel and API development teams can help you architect schemaless storage for rapid feature iteration while maintaining query performance and data integrity.