수색…


통사론

  • public function map (Router $ router) // 애플리케이션의 경로를 정의합니다.
  • protected function mapWebRoutes (Router $ router) // 애플리케이션의 "웹"경로를 정의합니다.

매개 변수

매개 변수 머리글
라우터 $ router \ Illuminate \ Routing \ Router $ router

비고

미들웨어는 경로에 대한 모든 호출이 경로 특정 코드를 실제로 치기 전에 미들웨어를 통과한다는 것을 의미합니다. Laravel에서 웹 미들웨어는 세션 처리 또는 csrf 토큰 검사를 보장하는 데 사용됩니다.

auth 또는 api와 같은 다른 미들웨어가 기본적으로 있습니다. 또한 자신의 미들웨어를 쉽게 만들 수 있습니다.

다른 미들웨어와 함께 api-routes 추가 및 기본 웹 미들웨어 유지

Laravel 버전 5.2.31부터 Web 미들웨어는 기본적으로 RouteServiceProvider ( https://github.com/laravel/laravel/commit/5c30c98db96459b4cc878d085490e4677b0b67ed)에 적용됩니다.

app / Providers / RouteServiceProvider.php에서 app / Http / routes.php 내의 모든 경로에 미들웨어를 적용하는 다음 함수를 찾을 수 있습니다

public function map(Router $router)
{
    $this->mapWebRoutes($router);
}

// ...

protected function mapWebRoutes(Router $router)
{
    $router->group([
        'namespace' => $this->namespace, 'middleware' => 'web',
    ], function ($router) {
        require app_path('Http/routes.php');
    });
}

보시다시피 미들웨어 웹이 적용됩니다. 여기서 이것을 변경할 수 있습니다. 그러나 다른 항목 (예 : routes-api.php)을 사용하여 API 경로를 다른 파일에 쉽게 추가 할 수도 있습니다.

public function map(Router $router)
{
    $this->mapWebRoutes($router);
    $this->mapApiRoutes($router);
}

protected function mapWebRoutes(Router $router)
{
    $router->group([
        'namespace' => $this->namespace, 'middleware' => 'web',
    ], function ($router) {
        require app_path('Http/routes.php');
    });
}

protected function mapApiRoutes(Router $router) 
{
    $router->group([
        'namespace' => $this->namespace, 'middleware' => 'api',
    ], function ($router) {
        require app_path('Http/routes-api.php');
    });
}

이를 통해 routes.php 내의 지저분한 그룹 래퍼없이 애플리케이션 경로에서 api 경로를 쉽게 분리 할 수 ​​있습니다.



Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow