Laravel Has Attributes
EAV Attributes in an handy Trait
, (*1)
This package provides a trait to attach attributes to any Eloquent model. The common use case is to add Settings to a model., (*2)
Attributes are stored following the Entity-Attribute-Value model. Data is abstracted using the Decorator pattern., (*3)
Install
Requires: Laravel >=5.4, (*4)
Composer, (*5)
composer require priblo/laravel-has-attributes
Laravel, (*6)
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, (*7)
Priblo\LaravelHasAttributes\LaravelServiceProvider::class,
Then run:, (*8)
php artisan vendor:publish --provider="Priblo\LaravelHasAttributes\LaravelServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Priblo\LaravelHasAttributes\LaravelServiceProvider" --tag="config"
Then migrate:, (*9)
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., (*10)
In the has-settings.php config file you can enable/disable caching and set the cache expiration time., (*11)
Caching is enabled by default, (*12)
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", (*13)
Roadmap
- More tests
- Expand README.MD