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

问题描述 投票:2回答:1

当我在线上传我的应用程序时遇到错误,尽管我的localhost上没有出现该错误

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()
    {
        //
    }
}
php laravel laravel-5.4
1个回答
1
投票

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

使用Illuminate \ Support \ Facades \ Schema;

在AppServiceProvider类的顶部我的问题解决了。

使用Laravel 5.8

© www.soinside.com 2019 - 2024. All rights reserved.