outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
273 stars 97 forks source link

Strange behaviour when using the helper in `web.php` #68

Closed 1stevengrant closed 3 years ago

1stevengrant commented 3 years ago

I can't quite work out what's happening here.

Locally, this works fine without any issues.

Package is installed and I can update via Nova no problem.

I have the following conditional in web.php

if (nova_get_setting('site_is_live')) {
    Route::get('/', SplashPageController::class);
} else {
    Route::get('/', function () {
        return view('index');
    });
}

However, when I attempt to deploy to Vapor environment

build:
      - 'composer install --no-dev'
      - 'php artisan event:cache'
      - 'npm ci && npm run prod && rm -rf node_modules'

I run into a db access error.

If I remove that conditional in web.php - it deploys just fine.

Can't figure out why.

Any ideas?

Tarpsvo commented 3 years ago

Hi! The issue is that web.php is fully executed when running artisan commands and nova_get_setting() tries to query the value from the database, which is not there during the build process. You should:

a) Run php artisan event:cache during startup of the web application b) Change how the routes are made to:

Route::get('/', function () {
        return nova_get_setting('site_is_live') ? (new SplashPageController)->index() :  view('index');
});