Yasser Moussa
Yasser Moussa

Reputation: 2329

class Schema not found in App Service Provider - even when i added use Schema;

I faced an error when i uploaded my application online although that error didn't appear on my localhost

enter image description here

Here is how my appserviceprovider.php look like

And before you say it i changed

use Illuminate\Support\Facades\Schema;

To

use Schema;

And i still have the same problem

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use DB;
use View;
use Request;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //Check for database connection
        try {
            DB::connection()->getPdo();
        } catch (\Exception $e) {
            if (Request::is('database/setup')) {
                echo View::make('common/database/setup', array('error' => $e->getMessage()));

                die();
            }
            else {
                echo View::make('errors/database', array('error' => $e->getMessage()));

                die();
            }
        }

        Schema::defaultStringLength(191);

       /*if (Schema::hasTable('categories')) {
           $categories = DB::table('categories')->get();

            view()->composer('frontend.layouts.include.header', function($view) use ($categories){
                $view->with('categories',$categories);
            });
       }

        if (Schema::hasTable('tags')) {
           $tags = DB::table('tags')->get();

            view()->composer('frontend.layouts.include.sidebar', function($view) use ($tags){
                $view->with('tags',$tags);
            });
        }*/
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Upvotes: 2

Views: 2469

Answers (1)

PHPFan
PHPFan

Reputation: 796

I had the same problem. So I just include

use Illuminate\Support\Facades\Schema;

at the top of AppServiceProvider class I and the problem solved.

using Laravel 5.8

Upvotes: 2

Related Questions