Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
camerongermein opened this issue Nov 23, 2023 · 6 comments
Closed

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

camerongermein opened this issue Nov 23, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@camerongermein
Copy link

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 camerongermein added the bug Something isn't working label Nov 23, 2023
@rawilk
Copy link
Owner

rawilk commented Nov 27, 2023

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

@maleointeractive
Copy link

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
Copy link

I am currently experiencing this, please what is the solution

@rawilk
Copy link
Owner

rawilk commented Mar 10, 2024

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
Copy link

resolved with changing context_serializer to DotNotationContextSerializer

ContextSerializer value not saving to DB correctly

@rawilk
Copy link
Owner

rawilk commented Oct 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants