在App Service Provider中找不到类Schema - 即使我添加了使用Schema;

时间:2017-07-13 08:10:22

标签: php laravel laravel-5.4

当我在线上传我的应用程序时遇到错误,尽管该错误并未出现在我的本地主机上

enter image description here

以下是我的appserviceprovider.php的样子

在你说它改变之前

use Illuminate\Support\Facades\Schema;

use Schema;

我仍有同样的问题

<?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()
    {
        //
    }
}

1 个答案:

答案 0 :(得分:0)

我有同样的问题。所以我只包括

使用Illuminate \ Support \ Facades \ Schema;

AppServiceProvider类I的顶部,问题已解决。

使用Laravel 5.8