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.
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
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
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"
- More tests
- Expand README.MD