You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running artisan route:cache throws exception:
exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in ..\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:95
After carefully inspecting the RouteCollection passed to the buildRouteCacheFile() function in the RouteCacheCommand.php, I see no indication that there are any closures in the collection.
I realize it's silly to define the 'home' route twice pointing to different controllers, but it seems like the wrong exception is being thrown in the above case.
The text was updated successfully, but these errors were encountered:
RouteCollection maintains 4 arrays of routes: $routes, $allRoutes, $nameList, and $actionList. After routes #1 and #2 are created for the 'home' path, route #2 overwrites route #1 in $routes and $allRoutes. But $actionList, which indexes Route instances by the controller-method "action" string, still holds route #1 ($nameList remains empty since you don't have named routes in this case). This is because $actionList is the only array for which the two routes have different indices ('App\Http\Controllers\WelcomeController@index' != 'App\Http\Controllers\HomeController@index').
In RouteCacheCommand::fire, the foreach loop iterates over the routes in $allRoutes, so it misses preparing route #1 (which is still in $actionList) for serialization. If, after the loop, you run
The line unset($this->container) in Route::prepareForSerialization stops the attempt at serializing the application which is responsible for the exception.
I stumbled upon this weird behavior when testing route caching. If I have a routes file containing only the following routes:
Route::get('home', 'WelcomeController@index');
Route::get('home', 'HomeController@index');
Running artisan route:cache throws exception:
exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in ..\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:95
After carefully inspecting the RouteCollection passed to the buildRouteCacheFile() function in the RouteCacheCommand.php, I see no indication that there are any closures in the collection.
I realize it's silly to define the 'home' route twice pointing to different controllers, but it seems like the wrong exception is being thrown in the above case.
The text was updated successfully, but these errors were encountered: