Laravel 5.2 升级 - 找不到类 AuthServiceProvider

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34636772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:59:11  来源:igfitidea点击:

Laravel 5.2 upgrade - class AuthServiceProvider not found

phplaravelexceptionlaravel-5upgrade

提问by ZarkDev

I'm currently spending time to upgrade my project from Laravel 4.2 to Laravel 5.2.

我目前正在花时间将我的项目从 Laravel 4.2 升级到 Laravel 5.2。

After lots of troubles I managed to get a 5.1 version running correctly so I started the 5.1 to 5.2 procedure as described in the official docs: https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0

经过很多麻烦,我设法让 5.1 版本正确运行,所以我开始了 5.1 到 5.2 的过程,如官方文档中所述:https: //laravel.com/docs/5.2/upgrade#upgrade-5.2.0

After the first step, my composer.jsonlooks like this:

第一步之后,我的composer.json看起来像这样:

"require": {
        "laravel/framework": "5.2.*",
        "illuminate/html": "5.*",
        "andywer/js-localization": "dev-laravel-5",
        "laracasts/flash" : "~1.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1",
        "symfony/dom-crawler": "~3.0",
        "symfony/css-selector": "~3.0"
    },
    "autoload": {
        "classmap": [
            "database",
            "app/Models",
            "app/Http/Controllers"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },

I also updated the app.php configto delete ArtisanServiceProvider and ControllerServiceProvider in the providers section.

我还更新了 app.php 配置以删除提供者部分中的 ArtisanServiceProvider 和 ControllerServiceProvider。

My app.php configlooks like this:

我的app.php 配置如下所示:

/*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => array(

        /*
         * Laravel Framework Service Providers...
         */
        'Illuminate\Auth\AuthServiceProvider',
        'Illuminate\Broadcasting\BroadcastServiceProvider',
        'Illuminate\Bus\BusServiceProvider',
        'Illuminate\Cache\CacheServiceProvider',
        'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
        'Illuminate\Cookie\CookieServiceProvider',
        'Illuminate\Database\DatabaseServiceProvider',
        'Illuminate\Encryption\EncryptionServiceProvider',
        'Illuminate\Filesystem\FilesystemServiceProvider',
        'Illuminate\Foundation\Providers\FoundationServiceProvider',
        'Illuminate\Hashing\HashServiceProvider',
        'Illuminate\Mail\MailServiceProvider',
        'Illuminate\Pagination\PaginationServiceProvider',
        'Illuminate\Pipeline\PipelineServiceProvider',
        'Illuminate\Queue\QueueServiceProvider',
        'Illuminate\Redis\RedisServiceProvider',
        'Illuminate\Auth\Passwords\PasswordResetServiceProvider',
        'Illuminate\Session\SessionServiceProvider',
        'Illuminate\Translation\TranslationServiceProvider',
        'Illuminate\Validation\ValidationServiceProvider',
        'Illuminate\View\ViewServiceProvider',
        /*
         * Application Service Providers...
         */
        'App\Providers\AppServiceProvider',
        'App\Providers\AuthServiceProvider',
        'App\Providers\EventServiceProvider',
        'App\Providers\RouteServiceProvider',

        // LIBS TIERCE
        JsLocalization\JsLocalizationServiceProvider::class,
        'Laracasts\Flash\FlashServiceProvider',

    ),

    /*
    |--------------------------------------------------------------------------
    | Service Provider Manifest
    |--------------------------------------------------------------------------
    |
    | The service provider manifest is used by Laravel to lazy load service
    | providers which are not needed for each request, as well to keep a
    | list of all of the services. Here, you may set its storage spot.
    |
    */

    'manifest' => storage_path().'/meta',

    /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => array(

        'App'       => Illuminate\Support\Facades\App::class,
        'Artisan'   => Illuminate\Support\Facades\Artisan::class,
        'Auth'      => Illuminate\Support\Facades\Auth::class,
        'Blade'     => Illuminate\Support\Facades\Blade::class,
        'Cache'     => Illuminate\Support\Facades\Cache::class,
        'Config'    => Illuminate\Support\Facades\Config::class,
        'Cookie'    => Illuminate\Support\Facades\Cookie::class,
        'Crypt'     => Illuminate\Support\Facades\Crypt::class,
        'DB'        => Illuminate\Support\Facades\DB::class,
        'Eloquent'  => Illuminate\Database\Eloquent\Model::class,
        'Event'     => Illuminate\Support\Facades\Event::class,
        'File'      => Illuminate\Support\Facades\File::class,
        'Gate'      => Illuminate\Support\Facades\Gate::class,
        'Hash'      => Illuminate\Support\Facades\Hash::class,
        'Lang'      => Illuminate\Support\Facades\Lang::class,
        'Log'       => Illuminate\Support\Facades\Log::class,
        'Mail'      => Illuminate\Support\Facades\Mail::class,
        'Password'  => Illuminate\Support\Facades\Password::class,
        'Queue'     => Illuminate\Support\Facades\Queue::class,
        'Redirect'  => Illuminate\Support\Facades\Redirect::class,
        'Redis'     => Illuminate\Support\Facades\Redis::class,
        'Request'   => Illuminate\Support\Facades\Request::class,
        'Response'  => Illuminate\Support\Facades\Response::class,
        'Route'     => Illuminate\Support\Facades\Route::class,
        'Schema'    => Illuminate\Support\Facades\Schema::class,
        'Session'   => Illuminate\Support\Facades\Session::class,
        'Storage'   => Illuminate\Support\Facades\Storage::class,
        'URL'       => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View'      => Illuminate\Support\Facades\View::class,
        'Form'      => 'Illuminate\Html\FormFacade',
        'HTML'      => 'Illuminate\Html\HtmlFacade',

        // FA?ADES TIERCES
        'Flash'             => 'Laracasts\Flash\Flash'

    ),

Of course, I cleared the config cachein bootstrap/cache and I tried everything I could to make it work but every time I run composer updateI get this error now:

当然,我清除了引导程序/缓存中的配置缓存,并尽我所能使其工作,但每次运行时composer update我都会收到此错误:

> php artisan clear-compiled


  [Symfony\Component\Debug\Exception\FatalErrorException]
  Class 'App\Providers\AuthServiceProvider' not found


Script php artisan clear-compiled handling the post-update-cmd event returned with an error



  [RuntimeException]
  Error Output:

worse than this, I can't run any artisan command or pages of my application. I keep getting this error any time I run some php in this project !

比这更糟糕的是,我无法运行任何 artisan 命令或我的应用程序页面。每当我在这个项目中运行一些 php 时,我都会收到这个错误!

This is some moves I tried:

这是我尝试过的一些动作:

  • Delete all caches including config cache and services.json (impossible to regenerate them because of the error in artisan commands)
  • delete the vendor folder and re-run composer update
  • delete the 'Illuminate\Auth\AuthServiceProvider',line from app.php config
  • 删除所有缓存,包括 config cache 和 services.json (由于 artisan 命令中的错误,无法重新生成它们)
  • 删除供应商文件夹并重新运行 composer update
  • 'Illuminate\Auth\AuthServiceProvider',从 app.php 配置中删除该行

None of this worked and I'm running out of fresh ideas. I have read and re-read the upgrade guide of the official docs and nothing seems to be related to this issue...

这些都没有奏效,我的新想法快用完了。我已经阅读并重新阅读了官方文档的升级指南,似乎没有任何与此问题相关的内容......

I'm still struggling with all that psr-4 / namespace thing in Laravel and I sense it can be caused something like that but can't figure out what exactly...

我仍然在为 Laravel 中的所有 psr-4 / 命名空间问题苦苦挣扎,我觉得它可能是由类似的事情引起的,但无法弄清楚究竟是什么......

采纳答案by Simon Bennett

Do you have this service provider in place App\Providers\AuthServiceProvider in the /app/Providers folder

你在 /app/Providers 文件夹中有这个服务提供者吗?

If not copy it from here and fix the namespace

如果不从这里复制它并修复命名空间

https://github.com/laravel/laravel/blob/master/app/Providers/AuthServiceProvider.php

https://github.com/laravel/laravel/blob/master/app/Providers/AuthServiceProvider.php

回答by Sari Yono

update

更新

    'Form'      => 'Illuminate\Html\FormFacade',
    'HTML'      => 'Illuminate\Html\HtmlFacade',

    // FA?ADES TIERCES
    'Flash'             => 'Laracasts\Flash\Flash'

I think those are causing your issues, try running it without those and check if these packages are 5.2 compatible. I also think that the Html component have been removed from the 5.* they should be maintained by collective so what you would need to do is to add the following rather than the Illuminate

我认为这些是导致您出现问题的原因,请尝试在没有这些的情况下运行它并检查这些软件包是否与 5.2 兼容。我还认为 Html 组件已从 5.* 中删除,它们应该由集体维护,因此您需要做的是添加以下内容而不是 Illuminate

'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',

Visit Laravel Collectives for more info

访问Laravel 集体以获取更多信息

回答by Shahrukh Anwar

Try putting below string inside inverted commas as follows, and try again

尝试将下面的字符串放在引号内,如下所示,然后再试一次

'JsLocalization\JsLocalizationServiceProvider::class',