The issue seems to be that the Router class is not properly bootstrapped with the application's routes. One solution is to override the getRoutes method in your Router class to return the application's routes instead of an empty RouteCollection. Here's an example implementation:
<?php
namespace App\Http\Responses;
use Illuminate\Routing\Router as BaseRouter;
class Router extends BaseRouter
{
/**
* Get the route collection for the application.
*
* @return \Illuminate\Routing\RouteCollection
*/
protected function getRoutes()
{
if (! $this->routes) {
$this->routes = $this->app['router']->getRoutes();
}
return $this->routes;
}
/**
* Static version of prepareResponse.
*
* @param $request
* @param $response
* @return \Symfony\Component\HttpFoundation\Response
*/
public static function toResponse($request, $response)
{
if ($response instanceof HttpResponse) {
return 'Hello instance of HttpResponse';
}
return parent::toResponse($request, $response);
}
}
This implementation overrides the getRoutes method to retrieve the application's routes from the container's router instance. This should ensure that your Router class has access to the application's routes.
Note that you may need to clear your application's cache after making this change to ensure that the new Router class is properly loaded. You can do this by running php artisan cache:clear.