Download the PHP package centrex/laravel-model-data without Composer
On this page you can find all versions of the php package centrex/laravel-model-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download centrex/laravel-model-data
More information about centrex/laravel-model-data
Files in centrex/laravel-model-data
Package laravel-model-data
Short Description Add virtual columns in any model of laravel
License MIT
Homepage https://github.com/centrex/laravel-model-data
Informations about the package laravel-model-data
Laravel Model Data
Serialize arbitrary attributes that donβt have dedicated columns into a JSON data field stored in a polymorphic model_datas table.
This package allows you to:
- Store flexible, schema-less data per model
- Access virtual attributes like native Eloquent properties
- Keep your core tables clean while supporting dynamic fields
- Use deterministic 32-character keys for efficient indexing
β¨ Features
- Transparent virtual attributes ($model->color)
- External storage via polymorphic model_datas table
- Deterministic 32-char hashed keys (md5)
- Supports multiple data namespaces via data_type
- Fully compatible with Eloquent casting
- Query support for JSON attributes
π¦ Installation
Usage
1. Add the trait to your model
2. Virtual Attributes (Transparent Mode)
// Retrieve β fully transparent, works like regular attributes
3. Structured Data (Explicit Mode)
You can also store grouped data explicitly:
Retrieve
4. Check / Delete
5. Query Virtual Attributes
6. Casting Support
Works seamlessly with Laravel casts:
βοΈ How It Works
Storage Model
Each record in model_datas represents:
Example:
Data Structure
π§ Design Modes
1. Transparent Mode (default)
- Works like native attributes
- Best for dynamic fields
2. Explicit Mode (recommended for structure)
- Namespaced data storage
- Better for large systems (ERP, SaaS)
ποΈ Advanced Usage
Multiple Data Types
Each stored separately but linked to the same model.
Access Nested Values
β‘ Performance Notes
- Primary key is fixed 32-char string
- Indexed for fast lookup
- No joins required for simple access
- JSON queries supported natively (MySQL / PostgreSQL)
β οΈ Best Practices
- Prefer explicit mode for complex systems
- Avoid overloading with deeply nested JSON
- Keep frequently queried fields as real columns
π§ͺ Testing
π Migration Strategy (from inline JSON)
If you're migrating from a data column:
- Move JSON to model_datas
- Drop old column
- Add trait
- Done
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- centrex
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-model-data with dependencies
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0