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

seanmccabe's avatar

Ziggy in Production causing ReflectionException

Attempting to deploy my laravel app to production and getting a ReflectionException:

[previous exception] [object] (ReflectionException(code: -1): Class \"Tightenco\Ziggy\BladeRouteGenerator\" does not exist at /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php:889)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(889): ReflectionClass->__construct()
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(770): Illuminate\Container\Container->build()
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(856): Illuminate\Container\Container->resolve()
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(706): Illuminate\Foundation\Application->resolve()
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->make()
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(120): Illuminate\Foundation\Application->make()
#6 /var/www/html/storage/framework/views/259dbce217202dbd010cc5f2e6a54ccec6f0d718.php(9): app()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): require('...')
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(110): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}()
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire()
#10 /var/www/html/vendor/livewire/livewire/src/ComponentConcerns/RendersLivewireComponents.php(69): Illuminate\View\Engines\PhpEngine->evaluatePath()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(70): Livewire\LivewireViewCompilerEngine->evaluatePath()
#12 /var/www/html/vendor/livewire/livewire/src/ComponentConcerns/RendersLivewireComponents.php(35): Illuminate\View\Engines\CompilerEngine->get()
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(195): Livewire\LivewireViewCompilerEngine->get()
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(178): Illuminate\View\View->getContents()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(147): Illuminate\View\View->renderContents()
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Response.php(69): Illuminate\View\View->render()
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Response.php(35): Illuminate\Http\Response->setContent()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(57): Illuminate\Http\Response->__construct()
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(87): Illuminate\Routing\ResponseFactory->make()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(338): Illuminate\Routing\ResponseFactory->view()
#21 /var/www/html/vendor/inertiajs/inertia-laravel/src/Response.php(110): Illuminate\Support\Facades\Facade::__callStatic()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(888): Inertia\Response->toResponse()
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(875): Illuminate\Routing\Router::toResponse()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Routing\Router->prepareResponse()
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#26 /var/www/html/vendor/inertiajs/inertia-laravel/src/Middleware.php(87): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Inertia\Middleware->handle()
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Auth\Middleware\EnsureEmailIsVerified->handle()
#30 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#32 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\AuthenticateSession->handle()
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Auth\Middleware\Authenticate->handle()
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle()
#41 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#42 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#43 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#44 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#45 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\Pipeline\Pipeline->then()
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\Routing\Router->runRouteWithinStack()
#48 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\Routing\Router->runRoute()
#49 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(729): Illuminate\Routing\Router->dispatchToRoute()
#50 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Illuminate\Routing\Router->dispatch()
#51 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#52 /var/www/html/vendor/livewire/livewire/src/DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#53 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Livewire\DisableBrowserCache->handle()
#54 /var/www/html/vendor/bref/laravel-bridge/src/Http/Middleware/ServeStaticAssets.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#55 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Bref\LaravelBridge\Http\Middleware\ServeStaticAssets->handle()
#56 /var/www/html/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#57 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#58 /var/www/html/app/Http/Middleware/Cors.php(23): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#59 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\Cors->handle()
#60 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#61 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#62 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#63 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#64 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#65 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#66 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#67 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#68 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#69 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#70 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#71 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\HandleCors->handle()#72 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#73 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle()
#74 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#75 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then()
#76 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#77 /var/www/html/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#78 {main}
"} 

I've no idea how to get passed this, I've set this up in other environments like my local, even in docker containers and never run into this.

Steps taken (as normally do):

  1. Composer Install
  2. composer install --ignore-platform-reqs --prefer-dist --no-scripts --no-progress --no-interaction --optimize-autoloader --no-dev
  3. composer dump-autoload
  4. php artisan optimize
  5. php artisan ziggy:generate
  6. npm install
  7. npm run prod

I've tried deleting the vendor and node_modules folders and reinstalling, trying running in local and running composer install and getting the dev packages.

Nothing seems to resolve this issue.

Bog standard blade files that aren't running through inertia are working without issue.

Would appreciate some help on this one, been banging my head against this for a while now.

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like the Tightenco\Ziggy\BladeRouteGenerator class is not being found, which could be due to a number of reasons. Here are some steps you can take to troubleshoot and resolve the issue:

  1. Check Ziggy Installation: Ensure that Ziggy is properly installed in your composer.json file and that you have run composer install without the --no-dev flag in your production environment, as Ziggy may be included in the require-dev section instead of require.

  2. Clear Caches: Sometimes, old cached files can cause issues. Clear all the caches using the following commands:

    php artisan cache:clear
    php artisan config:clear
    php artisan route:clear
    php artisan view:clear
    
  3. Optimize Clear: Since you've run php artisan optimize, you might also want to clear the optimization files:

    php artisan optimize:clear
    
  4. Permissions: Check the permissions of the storage and bootstrap/cache directories. They should be writable by the web server user.

  5. Autoloading: After clearing the caches, run the following command to regenerate the autoload files:

    composer dump-autoload
    
  6. Ziggy Generate: After clearing caches and regenerating autoload files, try running the Ziggy generate command again:

    php artisan ziggy:generate
    
  7. Check Environment: Ensure that your .env file is correctly set up for your production environment and that there are no environment-specific configurations causing the issue.

  8. Check for Typos: Ensure that there are no typos or case sensitivity issues in your namespaces or class names, as Linux servers are case-sensitive.

  9. Check Service Providers: Make sure that Ziggy's service provider is registered in your config/app.php file under the providers array.

  10. Composer Install: If you've previously run composer install with the --no-dev flag, make sure to run it without that flag in case Ziggy is a dev dependency:

    composer install --optimize-autoloader
    
  11. Check Compiled Views: If you have compiled views in your storage/framework/views directory, try clearing them out. Sometimes, a stale view can cause issues.

  12. Check for Package Updates: Check if there are any updates for Ziggy or related packages that might fix the issue.

If none of these steps resolve the issue, you may want to check the GitHub issues for the Ziggy package or seek further assistance from the community, as there might be a specific bug or compatibility issue at play.

3 likes
Jscott's avatar

I ran into this while upgrading Ziggy to version 2.

I found that running php artisan optimize did not refresh everything. For some reason the namespace change between Ziggy v1 and v2 did not force all the autoload files to be refreshed. Run this to start fresh.

php artisan optimize:clear

So the bot was right, but if you're curious why or which solution worked this is what I found.

3 likes

Please or to participate in this conversation.