laravel-settings icon indicating copy to clipboard operation
laravel-settings copied to clipboard

all() method not working with context()?

Open camerongermein opened this issue 1 year ago • 5 comments

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

camerongermein avatar Nov 23 '23 08:11 camerongermein

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

rawilk avatar Nov 27 '23 13:11 rawilk

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 👍

maleointeractive avatar Feb 01 '24 21:02 maleointeractive

I am currently experiencing this, please what is the solution

browynlouis avatar Feb 08 '24 11:02 browynlouis

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.

rawilk avatar Mar 10 '24 22:03 rawilk

resolved with changing context_serializer to DotNotationContextSerializer

ContextSerializer value not saving to DB correctly

KolyaSirik avatar Sep 26 '24 14:09 KolyaSirik

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.

rawilk avatar Oct 16 '24 15:10 rawilk