Laravel 7: 캐시 경로 오류

3590 단어 phplaravel
하위 폴더에 laravel 프로젝트를 만들고 하위 도메인별로 액세스 구성을 수행하는 것이 일반적입니다. https://mydomain.com/aliasdomain , generally, this has been supported and at the time of caching the routes hasn't been generated a type of conflict, however, in laravel 7 this has generated a mistake in the routes that are specified as:
Route::get('/', '.....')

A solution implemented in a project to solve this problem with the route cache was:

  1. Create a middleware with the following validation:
class RouteCache 
{
    public function handle(Request $request, Closure $next)
    {
        if ($request->path() === '/') {
            $newURI = $request->server->get('REQUEST_URI') . 'index.php';
            $request->server->set('REQUEST_URI', $newURI);
        }

        return $next($request);
    }
}
  1. Add the middleware to the Kernel file in the middleware array:
protected $middleware = [
    ....,
    \App\Http\Middleware\RouteCache::class,
];

With this, what is achieved is that if a route / is declared within the project, the middleware validates when trying to access it and overwrites the REQUEST_URI value that the request carries by adding index.php (this will continue being transparent to the end user)

좋은 웹페이지 즐겨찾기