Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

skoobi's avatar
Level 13

Global Settings Config Migration Issue

Hi. I've got a SettingsServiceProvider class that gets the site settings from the database and caches it so the config item can be used all through the app. The issue im getting is once i deploy to the test server the code executes before it gets a chance to migrate the settings table and so it fails. This is using Laravel Forge to deploy. Is there a way to call the service only if the table exists?

Heres the service provider.

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Cache\Factory;
use App\Models\AppSetting;

class SettingServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot(Factory $cache, AppSetting $settings = null)
    {
        $settings = $cache->remember('settings', 60, function() use ($settings){
            return $settings->pluck('value', 'name')->all();
        });
        config()->set('settings', $settings);
    }
}

Many thanks

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

You can use Schema::hasTable('settings') to determine whether the table exists. So, something like the following could work:

$settings = $cache->remember('settings', 60, function() use ($settings){
    return Schema::hasTable('settings') ? $settings->pluck('value', 'name')->all() : [];
});
skoobi's avatar
Level 13

Thanks @tykus, I didn't even think about using Schema. That worked, thank you.

Please or to participate in this conversation.