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

Error: "A facade root has not been set" when calling settings helper on config files #9

Closed metadevstudio closed 5 months ago

metadevstudio commented 1 year ago

Error when trying to use the settings helper on some config file like "config/app.php":

A facade root has not been set. {"exception":"[object] (RuntimeException(code: 0): A facade root has not been set. at nova/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:350) [stacktrace]

0 nova/vendor/stepanenko3/nova-settings/src/helpers.php(27): Illuminate\Support\Facades\Facade::__callStatic()

leonardyrj commented 9 months ago

I'm also having the same problem. This error happens because the help settings calls the Cache::remember facade, I think it has not yet been initialized in the service container. Now I don't know if there is an alternative for this.

stepanenko3 commented 5 months ago

Hi, @metadevstudio, @leonardyrj For Laravel, it is not normal to make queries in config files. You can create Middleware like LoadGlobalConfig, in which you can do the following:

class LoadGlobalConfig
{
    public function handle(Request $request, Closure $next): Response
    {
        config([
            'key' => settings(...),
         ]);
    }
}