Attrify

Eloquent’s missingdynamic attributes.

Sometimes you just want to attach attributes without a migration.

A project from
Obelaw
composer require obelaw/attrify

MIT Licensed · Free forever · Obelaw Packages

Overview

Attrify lets you attach dynamic attributes to any Eloquent model without altering the database schema for each new attribute, using the Entity-Attribute-Value (EAV) pattern to store data flexibly.

Key features

  • Simple trait integration for any model
  • Support for text, integer, boolean, date & more
  • Efficient caching of attribute definitions
  • Validation rule integration

Basic usage

use Obelaw\Attrify\Traits\HasAttributes;

class Product extends Model
{
    use HasAttributes;
}

$product->setAttr('color', 'red');
$product->save();

echo $product->getAttr('color'); // Output: red
Awesome contributors