rawilk / laravel-settings

Store Laravel application settings in the database.
https://randallwilk.dev/docs/laravel-settings
MIT License
199 stars 17 forks source link

all() method not working with context()? #49

Closed camerongermein closed 1 month ago

camerongermein commented 1 year ago

Laravel Settings

3.3.0

Laravel Version

v10.26.2

Bug description

Not sure if I'm doing something wrong, or this isn't supported? The documentation doesn't seem to specify.

Settings::context($model->context())->set('test', 'value');
Settings::context($model->context())->get('test'); //returns 'value'
Settings::context($model->context())->all(); //returns an empty Collection

Steps to reproduce

Using the code above, execute it with the context of any simple Eloquent Model.

Relevant log output

No response

rawilk commented 1 year ago

You should be able to use all with context. I'll look into this further to see if I can replicate it.

maleointeractive commented 10 months ago

Hi, I just found this package which seems good for my needs but I have the same problem.

// Storing settings

$context = new Context(['user_id' => $request->get('user_id']);
$request->get('settings')->each(function($value, $key) use($context) {
    Settings::context($context)->set($key, $value);
});

// -> Settings are good in DB

// Retrieving settings

$context = new Context(['user_id' => $user->id]);
$settings = settings()->context($context)->all();

// -> $settings is an empty Collection

I would be nice if $settings where well filled correctly 👍

browynlouis commented 9 months ago

I am currently experiencing this, please what is the solution

rawilk commented 8 months ago

I haven't had a chance to look into this issue yet, so if someone is able to resolve the issue before I do, please feel free to PR a fix for it. I plan on trying to fix it at some point; just not sure when I'll be able to.

KolyaSirik commented 2 months ago

resolved with changing context_serializer to DotNotationContextSerializer

ContextSerializer value not saving to DB correctly

rawilk commented 1 month ago

Using the DotNotationContextSerializer should be the solution to this, as pointed out by @KolyaSirik. I'll update the docs to mention this.

I'm going to close this issue, but feel free to re-open if using that serializer doesn't work for you.