Open theVannu opened 3 years ago
If anyone comes across an issue like this one. A general approach for "dynamic values" in config files is to set the desired configuration items at runtime like this:
Example for Admin:
config([
'user-preferences.database.table' => 'admin',
'user-preferences.cache.prefix' => 'user-admin-',
'user-preferences.cache.suffix' => '-preferences-admin',
]);
To achieve this I would create a new Listener
that reacts to the Illuminate\Auth\Events\Login
Determine what type of login this is and then set the configuration appropriately.
Ref: https://laravel.com/docs/11.x/events#generating-events-and-listeners
Hi all, I would like to describe a possible (little) problem and propose possible solutions Consider following scenario:
We have a multi guard application with the following auth.php configuration
As you can se a "logged-user" can be a user or an admin Suppose that we want use this package for manage the preference of both type of users, so we have a column prefernces on table users and admin. I think we have two possible strategies:
1) Simply create a before middleware and set configuration user-preferences.php at runtime, for example if we want manage the preferences for Admin we set the configuration file as:
As you can see this strategy doesn't need modify to the package code.
2) Second strategy, change the configuration file in order to manage multi guard application, for example:
So in the class UserPreferences,php we can check the guard and choose the right configuration (this is a breaking change!).
The question is, what is the better strategy in your opinion? Change the package code? Or simply write some DOC in order to show some example on "How to resolve the multi-guard problem" ?
Thank you, Gianluca.