dou47732
dou47732
2016-04-11 03:08

致命错误:在生产中安装composer之后找不到类'LaravelLocalization'

已采纳

It's been 3 days since I'm working on translating my site, so I installed LaravelLocalization:

I did everything working in local, then I pushed it in production and executed:

composer install --no-interaction --no-dev
php artisan clear-compiled
php artisan optimize
composer dump-autoload -o
php artisan route:cache
php artisan config:cache

Now, all the "php artisan commands fail with:"

 [Symfony\Component\Debug\Exception\FatalThrowableError]  
 Fatal error: Class 'LaravelLocalization' not found       

In this case, in the composer install script, it fails in:

php artisan clear-compiled

I tried to run:

php artisan cache:clear
php artisan route:clear

But without any results...

Any ideas??? This is not the first time I get this kind of stuff, but I may say that this it's a pain in the ass :(

EDIT:

In my routes.php,

I deleted this line:

Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect']],

around all my routes, and now composer install works.

But it doesn't solve my issue, because as soon as I put it back, I still get the same error :(

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dongsui8162 dongsui8162 5年前

    I resolved it removing the line:

    Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect']], 
    

    in my file routes.php

    run again

    composer install
    

    and finally

    php artisan config:clear
    php artisan route:clear
    

    What I don't know is why it happened, and if there is a way to prevent it...

    点赞 评论 复制链接分享
  • douda5227 douda5227 5年前

    This has been a known issue for a while, but has actually finally been resolved recently. You can read about the issue here.

    Basically, running php artisan loads the entire framework, including the cached files. Since the cached files don't have your service provider, you get the error. This includes running php artisan clear-compiled. So, it is using the cached files in the command that is used to delete the cached files.

    This issue has finally been resolved as of laravel/framework:v5.2.25 and laravel/laravel:v5.2.27, and backported to laravel/framework:v5.1.33 and laravel/laravel:v5.1.33.

    This fix includes a change to the Laravel application (laravel/laravel), in addition to the Laravel Framework (laravel/framework). To implement, you will need to:

    1) Update the scripts section of your composer.json file to match that in the laravel/laravel package. Specifically:

    • remove the pre-update-cmd section
    • in the post-install-cmd section, replace "php artisan clear-compiled" with "Illuminate\\Foundation\\ComposerScripts::postInstall"
    • in the post-update-cmd section, replace "php artisan clear-compiled" with "Illuminate\\Foundation\\ComposerScripts::postUpdate"

    2) Once you have updated your composer.json, run a composer update. If you only want to update the framework, you can run composer update laravel/framework.

    点赞 评论 复制链接分享
  • ds15812330851 ds15812330851 5年前

    as what the error says, it means that the composer can't locate your package. so be sure to check your config/app.php file be sure to put the package in providers and aliases arrays, respectively.

    点赞 评论 复制链接分享

相关推荐