Replies: 2 comments 2 replies
-
I would suggest creating a data object which can be constructed from the settings class, role (some metafield, haven't used that package in a while) and user (just a json payload field). That way you can define settings for each level. |
Beta Was this translation helpful? Give feedback.
-
@rubenvanassche Thank you for your suggestion/idea. @linjection My solution looks like this: I created a new db table Schema::create('model_has_settings', function (Blueprint $table) {
$table->id();
$table->morphs('model');
$table->string('group')->index();
$table->string('name');
$table->json('payload');
$table->timestamps();
}); The columns group, name and payload are from the settings' migration. The model-morph is used to identify the model (user or role). After that I created a trait for the models which is responsible for fetching the settings from cache or DB and saving to cache/DB. I also extended the Settings class with an array which contains the setting-props that could be set by models. At least there is an event listener for It's not perfect, but I hope you can use it. I still have no clue how to tackle the migrations and clearing the cache with the built-in functionality. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
I use this repo and spatie/laravel-permission and wondered what would be the best way to implement role or user specific settings. Do you have any ideas or suggestions?
My intention is that there are default system-wide settings and some of them should be set dependent of the role. The user should have the possibility to overwrite them as user specific settings, too. This results in a kind of settings-hierarchy.
Beta Was this translation helpful? Give feedback.
All reactions