Error in RouteCacheCommand.php when running php artisan route:cache
I am encountering an error when trying to run the php artisan route:cache command in Laravel 9 with PHP 8.2. The error message I am receiving is:
Illuminate\Foundation\Console\RouteCacheCommand::buildRouteCacheFile(): Argument #1 ($routes) must be of type Illuminate\Routing\RouteCollection, Illuminate\Routing\CompiledRouteCollection given, called in /root/vendor/laravel/framework/src/Illuminate/Foundation/Console/RouteCacheCommand.php on line 79
It seems that the Illuminate\Foundation\Console\RouteCacheCommand::buildRouteCacheFile() method is expecting an instance of Illuminate\Routing\RouteCollection as the first argument $routes, but it received an instance of Illuminate\Routing\CompiledRouteCollection.
This error occurs because the php artisan route:cache command expects an instance of Illuminate\Routing\RouteCollection as the first argument, but it is receiving an instance of Illuminate\Routing\CompiledRouteCollection. To fix this, you can clear the route cache by running the php artisan route:clear command and then regenerate the route cache by running the php artisan route:cache command again.
If the issue persists, you can try updating your Laravel version to the latest version or downgrading your PHP version to a stable version.