Juliatzin
Juliatzin

Reputation: 19705

Fatal error: Class 'LaravelLocalization' not found after composer install in production

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 :(

Upvotes: 4

Views: 6927

Answers (3)

patricus
patricus

Reputation: 62338

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.

Upvotes: 1

Juliatzin
Juliatzin

Reputation: 19705

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...

Upvotes: 2

Rolandoz
Rolandoz

Reputation: 11

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.

Upvotes: 1

Related Questions