You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just missing a feature here to retrieve all models by given setting. Of all settings packages, this was one of the cleanest, so I implemented more or less a prototype version using a facade.
I believe the code below can be optimised, but it's enough to get the general idea. If you are interested I could start a PR.
I'm using a Facade (Settings) and implemented a single static method into the HasModelSettings trait.
Use case
I need to extract all models with a certain settings value, e.g. database version or revision. I wanted something simple as Settings::findAll('database.revision', '1.1') and retrieve all models with this value, filter the models I need e.g. Settings::findAll([User::class, Document::class], 'database.revision', '1.1').
This also includes for specific models as in User::findSetting('database.revision', '1.1') using the static method in the HasModelSettings trait.
/**
* In any register method of a provider, e.g. AppServiceProvider
*/
public function register() {
$this->app->bind('settings', function() {
return new ModelSettingsHelper;
});
}
This discussion was converted from issue #61 on April 07, 2021 20:15.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Great work on this package.
I'm just missing a feature here to retrieve all models by given setting. Of all settings packages, this was one of the cleanest, so I implemented more or less a prototype version using a facade.
I believe the code below can be optimised, but it's enough to get the general idea. If you are interested I could start a PR.
I'm using a Facade (
Settings
) and implemented a single static method into theHasModelSettings
trait.Use case
I need to extract all models with a certain settings value, e.g. database version or revision. I wanted something simple as
Settings::findAll('database.revision', '1.1')
and retrieve all models with this value, filter the models I need e.g.Settings::findAll([User::class, Document::class], 'database.revision', '1.1')
.This also includes for specific models as in
User::findSetting('database.revision', '1.1')
using the static method in theHasModelSettings
trait.And this should be registered in any available provider and in the
config/app.php
inaliases
Beta Was this translation helpful? Give feedback.
All reactions