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

BerlinCalling's avatar

Migration fails because of service provider

Hello,

I have a Service Provider that loads all my global settings from a db table and puts it into the config

    public function boot(Factory $cache, Setting $settings)
    {
        $settings = $cache->remember('settings', 3600, function() use ($settings)
        {
            return $settings->lists('config_value', 'name')->all();
        });

        config()->set('settings', $settings);
    }

The problem is, when someone tries to setup the project the migration will not run because it throws an error because of the missing table. Is there a way to check if a migration is run or a table exists so that the migration works without constantly commenting the service provider out before migrating?

0 likes
8 replies
CamKem's avatar

@marcosvca Please don't respond to old threads as it blocks up the forum. If you have a question, or want to discuss something create a new thread!

BerlinCalling's avatar

@tomi thanks, I missed that, but I still can't figure out how I would use Schema in the settings provider?

simondavies's avatar

the problem i think is that on initial set up or running is that it will load all the application first etc and thus runs the service providers etc, thus if yours is reliant on the db first being set up then you might need to put in your readme file, and let them know after initial install etc add the service provider. What the actual error your getting?

akmalelias's avatar

@themightystephen Thank you, it works by using this solution. Just wondering, is this operation is expensive and will affect the performance? Because it will be executed every time right?

maclagan's avatar

I had a similar problem and ended up using try catch blocks

try {
            // Your super fun database stuff

       }  catch (\Exception $e) {
    // do nothing
      }
1 like

Please or to participate in this conversation.