Download the PHP package abdylreshit/laravel-eav without Composer
On this page you can find all versions of the php package abdylreshit/laravel-eav. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abdylreshit/laravel-eav
More information about abdylreshit/laravel-eav
Files in abdylreshit/laravel-eav
Package laravel-eav
Short Description A lightweight EAV package for Laravel: add dynamic, typed attributes to any Eloquent model with validation and easy querying.
License MIT
Homepage https://github.com/abdylreshit/laravel-eav
Informations about the package laravel-eav
Laravel EAV
A lightweight, powerful EAV (Entity-Attribute-Value) package for Laravel. Add dynamic, typed attributes to any Eloquent model without modifying your database schema. Perfect for e-commerce platforms, CMS systems, and applications requiring flexible data structures.
Features
✨ Dynamic Attributes - Add unlimited attributes to any model without schema changes
🎯 Type Support - String, text, integer, decimal, boolean, date, datetime, JSON, image, and file types
✅ Validation Ready - Built-in validation support for attribute values
🔍 Easy Querying - Filter models by EAV attributes with fluent API
🌍 Translatable - Support for multi-language attribute names
📦 Zero Configuration - Works out of the box with sensible defaults
🚀 Performance Optimized - Efficient queries with eager loading support
Installation
Install the package via Composer:
The package will auto-discover and register its service provider.
Configuration
Publish the migration:
Run the migration:
This creates the necessary tables: attributes and attribute_values.
Quick Start
1. Add the Trait to Your Model
2. Create Attributes
3. Use Attributes on Your Model
Querying with Attributes
Filter models by attribute values:
Attribute Types
The package supports the following attribute types:
| Type | Description | Column |
|---|---|---|
| STRING | Short text | string_value |
| TEXT | Long text | text_value |
| INTEGER | Whole numbers | integer_value |
| DECIMAL | Decimal numbers | decimal_value |
| BOOLEAN | True/false | boolean_value |
| DATE | Date (Y-m-d) | date_value |
| DATETIME | DateTime (Y-m-d H:i:s) | datetime_value |
| JSON | JSON data | json_value |
| IMAGE | Image file | image_value |
| FILE | File attachment | file_value |
Define Attribute Type
Translatable Attributes
Attribute names are translatable out of the box:
Eager Loading
Eager load EAV values with your model to avoid N+1 queries:
Validation
Validate EAV attributes in your request:
Available Methods
Getting Attributes
getAttribute(string $code)- Get a single attribute valuegetAttributes(array $codes)- Get multiple attribute valuesgetAllAttributes()- Get all attributes as an arrayhasAttribute(string $code)- Check if attribute exists
Setting Attributes
setAttribute(string $code, $value)- Set a single attributesetAttributes(array $attributes)- Set multiple attributes
Deleting Attributes
deleteAttribute(string $code)- Delete an attribute value
Querying
whereAttribute(string $code, $value)- Filter by single attributewhereAttributes(array $attributes)- Filter by multiple attributes
Relationships
eavValues()- MorphMany relationship to attribute values
Database Schema
Attributes Table
Attribute Values Table
Examples
E-Commerce Product Catalog
CMS Page Attributes
Performance Tips
- Use Eager Loading - Always eager load EAV values when querying multiple models
- Index the code Column - Add a database index to
attributes.codefor faster queries - Cache Attributes - Cache commonly used attributes
- Batch Operations - Use batch setting/getting instead of individual calls
Console Commands
Publish Assets
Publishes migrations and configuration files.
Migrate EAV Tables
Runs EAV-specific migrations.
Troubleshooting
Attribute Not Found
Ensure the attribute exists before setting a value:
N+1 Query Problem
Use eager loading:
Type Mismatch
Ensure the value type matches the attribute type:
License
The Laravel EAV package is open-sourced software licensed under the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For support, please open an issue on the GitHub repository.
Changelog
See CHANGELOG.md for recent changes.
Credits
Created by Abdylreshit
Made with ❤️ for Laravel developers
All versions of laravel-eav with dependencies
illuminate/support Version ^12.0
illuminate/database Version ^12.0
illuminate/console Version ^12.0
spatie/laravel-translatable Version ^6.11