priblo/laravel-has-attributes

EAV based attributes as a Trait

v1.3.0 2019-02-04 00:45 UTC

This package is auto-updated.

Last update: 2024-04-30 00:27:56 UTC


README

EAV Attributes in an handy Trait

Build Status Codacy Badge

This package provides a trait to attach attributes to any Eloquent model. The common use case is to add Settings to a model.

Attributes are stored following the Entity-Attribute-Value model. Data is abstracted using the Decorator pattern.

Install

Requires: Laravel >=5.4

Composer

    composer require priblo/laravel-has-attributes

Laravel

This package supports Auto Discovery. If your Laravel version doesn't support it or you have disabled it, you can install this package by adding to the 'providers' array in ./config/app.php

Priblo\LaravelHasAttributes\LaravelServiceProvider::class,

Then run:

php artisan vendor:publish --provider="Priblo\LaravelHasAttributes\LaravelServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Priblo\LaravelHasAttributes\LaravelServiceProvider" --tag="config"

Then migrate:

php artisan migrate

Cache

Caching requires a driver which supports tags. File and Database won't work, redis is suggested. Please make sure to either disable caching in the config or use the array driver for local development.

In the has-settings.php config file you can enable/disable caching and set the cache expiration time.

Caching is enabled by default

Notes

Please do remember that each of the settings in a EAV model are set in a TEXT field, thus a value of true will be stored as "1"

Roadmap

  • More tests
  • Expand README.MD