Problem in App Service Provider

Published 4 months ago by herrygallery

Problem:

In Providers - App Service Provider, I wrote :

View::share('publicoption', DB::table('options')->first());

Then I manually drop all of my tables from XAMPP including Options table above to test my migration and seed. Then got error :

SQLSTATE[42S02]: Base table or view not found: 1146

If I delete the above code in the App Service Provider, everything works OK.

Is my code wrong? Do I have to adjust the code in App Service Provided to refresh my tables?

Thanks

rin4ik
rin4ik
4 months ago (266,140 XP)

just run php artisan migrate . it is looking for table options which doesn't exist

tykus
tykus
4 months ago (690,060 XP)

You can't just run php artisan migrate because the same Base table or view not found exception will occur. Ideally, you would not have a DB query inside a ServiceProvider, but since you do, you will need to comment out that line before you can run migrations.

As a longer term solution, you could wrap that line in a try catch so that the QueryException does not prevent running the migrations in the first instance.

herrygallery

@tykus thanks for the suggestions. I will try that, its new for me. Using DB query inside the View share is just so convenient, because I have so many options regarding user preference e.g. colors, thumbnail image per row, collapse in/out, pagination, width and height of sketchpad js, etc.

Please sign in or create an account to participate in this conversation.