Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Marchius's avatar

Upgrading to Laravel 7 Uncaught ReflectionException: Class translator does not exist

I have upgraded laravel from 5.8 to 7 on my local setup successfully, now I'm trying to push these changes and upgrade it on production server. All seems to be fine, composer update ran without errors, all packages were successfully upgraded. The problem is - I get this error when I try to open my page

Got error 'PHP message: PHP Fatal error: Uncaught ReflectionException: Class translator does not exist in /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php:809\nStack trace:\n#0 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(809): ReflectionClass->__construct('translator')\n#1 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(691): Illuminate\Container\Container->build('translator')\n#2 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\Container\Container->resolve('translator', Array, true)\n#3 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(637): Illuminate\Foundation\Application->resolve('translator', Array)\n#4 /var/www/vhosts/testsite/httpdocs/vendor/...PHP message: PHP Fatal error: Uncaught ReflectionException: Class translator does not exist in /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php:809\nStack trace:\n#0 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(809): ReflectionClass->__construct('translator')\n#1 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(691): Illuminate\Container\Container->build('translator')\n#2 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\Container\Container->resolve('translator', Array, true)\n#3 /var/www/vhosts/testsite/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(637): Illuminate\Foundation\Application->resolve('translator', Array)\n#4 /var/www/vhosts/testsite/httpdocs/vendor/...'

I have tried running composer dump-autoload, I have also tried deleting bootstrap/cache files, I even tried removing vendor folder and running composer to install all of the packages again. None of those help.

Here's my composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "cybercog/laravel-love": "^8.6",
        "doctrine/dbal": "^2.0",
        "fideloper/proxy": "^4.0",
        "itsgoingd/clockwork": "^5.1",
        "jorenvanhocht/laravel-share": "^4.1",
        "laravel/framework": "^7.0",
        "laravel/helpers": "^1.4",
        "laravel/sanctum": "^2.13",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^2.0",
        "mews/purifier": "3.3.6",
        "predis/predis": "^1.1",
        "rafikhaceb/tcpdi": "dev-master",
        "setasign/fpdf": "1.8.*",
        "setasign/fpdi": "^2.0",
        "spatie/laravel-cookie-consent": "2.12.13",
        "spatie/laravel-medialibrary": "^7.0.0",
        "tohidplus/laravel-vue-translation": "^2.1",
        "tymon/jwt-auth": "1.0.*"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~8.5",
        "symfony/thanks": "^1.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

I also don't use trans() anywhere in my code (nor config files). Any help would be appreciated.

0 likes
7 replies
Nakov's avatar

Try checking if you have this line in your app/config.php file:

Illuminate\Translation\TranslationServiceProvider::class,

and run composer dump-autoload as well. php artisan config:clear in case the configuration has been cached.

Sinnbeck's avatar

Check if you are using trans() outside of blade files. Maybe you are using it before it has been loaded

Marchius's avatar

@Sinnbeck Searched through the whole project, overall the only place it's used is a cookie consent, which is a blade file. I use __() syntax though, but these are also used only inside controllers and blade files

Marchius's avatar

A theory I have is that somehow that's a case-sensitivity issue? I mean it does say in the error Class translator does not exist with a lowercase t for translator. I'm not sure how this helps in any way, just a thought

Marchius's avatar
Marchius
OP
Best Answer
Level 1

I got it working, apparently it was an issue with a completely different package which was mentioned nowhere in the error message. After removing that package ("itsgoingd/clockwork") everything started working fine.

4 likes
dcranmer's avatar

I had this exact same issue (with Laravel 9). Removing clockwork fixed it.

Please or to participate in this conversation.