pilat
708
1
Laravel

Troubleshooting "Serialization of Closure is not allowed" issue when caching routes

Posted 11 months ago by pilat

I'm trying to cache routes in Laravel 5.3-based project. Here's the error I get:

$ php artisan route:cache -v

Route cache cleared!


  [Exception]
  Serialization of 'Closure' is not allowed


Exception trace:
 () at /Users/pilat/version-control/mappanel/vendor/laravel/framework/src/Illuminate/Foundation/Console/RouteCacheCommand.php:95
 serialize() at /Users/pilat/version-control/mappanel/vendor/laravel/framework/src/Illuminate/Foundation/Console/RouteCacheCommand.php:95
 Illuminate\Foundation\Console\RouteCacheCommand->buildRouteCacheFile() at /Users/pilat/version-control/mappanel/vendor/laravel/framework/src/Illuminate/Foundation/Console/RouteCacheCommand.php:65
 Illuminate\Foundation\Console\RouteCacheCommand->fire() at n/a:n/a
 call_user_func_array() at /Users/pilat/version-control/mappanel/vendor/laravel/framework/src/Illuminate/Container/Container.php:508
 Illuminate\Container\Container->call() at /Users/pilat/version-control/mappanel/vendor/laravel/framework/src/Illuminate/Console/Command.php:169
 Illuminate\Console\Command->execute() at /Users/pilat/version-control/mappanel/vendor/symfony/console/Command/Command.php:261
 Symfony\Component\Console\Command\Command->run() at /Users/pilat/version-control/mappanel/vendor/laravel/framework/src/Illuminate/Console/Command.php:155
 Illuminate\Console\Command->run() at /Users/pilat/version-control/mappanel/vendor/symfony/console/Application.php:817
 Symfony\Component\Console\Application->doRunCommand() at /Users/pilat/version-control/mappanel/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at /Users/pilat/version-control/mappanel/vendor/symfony/console/Application.php:116
 Symfony\Component\Console\Application->run() at /Users/pilat/version-control/mappanel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121
 Illuminate\Foundation\Console\Kernel->handle() at /Users/pilat/version-control/mappanel/artisan:35

Important notes:

  • I've already moved all Closures from route/*.php files to controllers and re-checked it several times. The only closures in these files remaining are in Route::group constructions.
  • I've tried a script like this, jut to be on the safe side (it returned nothing):
# tinker

$routes = app('router')->getRoutes()

foreach ($routes as $route) {
    if (is_object($route) && ($route instanceof Closure)) {
        $r = new ReflectionFunction($route);
        dump($r->getFilename());
    }
}

What are my next steps?

Please sign in or create an account to participate in this conversation.