Associate generic data to any other model without polluting your application model logic.
cloudcake/laravel-settings is a Laravel package for associate generic data to any other model without polluting your application model logic..
It currently has 0 GitHub stars and 116 downloads on Packagist (latest version v1.2).
Install it with composer require cloudcake/laravel-settings.
Discover more Laravel packages by cloudcake
or browse all Laravel packages to compare alternatives.
Last updated
Settings is a package to assist in associating settings or attributes of JSON form to any of your models using polymorphic relationships.
php artisan vendor:publish --provider="Settings\Providers\SettingsServiceProvider" \
--tag="migrations"
Add the \Settings\Traits\HasSettings trait to any model that should have settings.
use Settings\Traits\HasSettings;
class User extends Model
{
use HasSettings;
}
use Settings\Models\Setting;
Setting::make('config', [
'rateLimit' => true,
'ipLocks' => [
'127.0.0.1',
'10.0.0.1'
]
]);
use Settings\Models\Setting;
Setting::make('preferences', [
'notifications' => true,
'backgroundColour' => '#ffffff'
], \App\User::class);
When attaching settings, any fields not provided will receive the default values.
\App\User::find(1)->attachSetting('preferences', [
'notifications' => false,
]);
The above will set notifications to true while backgroundColour will be inherited from the original setting. If the global setting is changed, the user's setting will return the changed setting.
\App\User::first()->setting('preferences');
\App\User::first()->setting('preferences')->get('notifications');
\App\User::first()->setting('preferences')->set('notifications', true);