Back to Labs

Attrify

Add dynamic EAV (Entity-Attribute-Value) attributes to any Eloquent model effortlessly.

composer require obelaw/attrify
Docs GitHub

Overview

Attrify allows you to attach dynamic attributes to your Laravel Eloquent models without altering the database schema for each new attribute. It uses the Entity-Attribute-Value (EAV) pattern to store data flexibly.

Key Features

  • Simple Trait integration for any Model
  • Support for various data types (Text, Integer, Boolean, Date, etc.)
  • Efficient caching of attribute definitions
  • Validation rule integration

Basic Usage

use Obelaw\Attrify\Traits\HasAttributes;

class Product extends Model
{
    use HasAttributes;
}

// Set a dynamic attribute
$product->setAttr('color', 'red');
$product->save();

// Get a dynamic attribute
echo $product->getAttr('color'); // Output: red