stepanenko3 / nova-settings

This Laravel Nova settings tool based on env, using nativ nova fields and resources
MIT License
31 stars 5 forks source link

Helper function does not work properly #2

Closed Specialistinwebsites closed 2 years ago

Specialistinwebsites commented 2 years ago

I have 2 issues with the helper function.

  1. Updating fields will not reset the cached value. You can manually fix this by listening to the events and resetting the cache.

  2. The helper will retrieve a value based on the "ENV" variable but will search in the database with the "ENV" and "TYPE" variable. So if you happen to use two types of settings you will mismatch the cached value. It will result in a blank value because the helper function won't search in the database as it already cached the other settings.

$settings = Cache::remember('settings.' . $env, config('cache.lifetime'), function() use ($section, $env) {
    return config('nova-settings.model')::query()
        ->select('settings')
        ->where('slug', $section)
        ->where('env', $env)
        ->first()
        ->settings ?? [];
});

It should instead be;

$settings = Cache::remember('settings.' . $env . $section, config('cache.lifetime'), function() use ($section, $env) {
    return config('nova-settings.model')::query()
        ->select('settings')
        ->where('slug', $section)
        ->where('env', $env)
        ->first()
        ->settings ?? [];
});
stepanenko3 commented 2 years ago

@Specialistinwebsites,

Huge thanks for your issue I fixed it in v1.0.3