1. 程式人生 > >laravel 配置路由 api和web定義的路由的區別

laravel 配置路由 api和web定義的路由的區別

1、路由經過中介軟體方面不同

開啟kerenl.php就可以看到區別

    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

2、路徑不一樣

在web.php寫的路由是這樣的

eg:http://quan.cms/backend/admin/add

在api.php寫的路由需要加上XXX/api/路由地址,相當於在web.php的基礎上加了一層api

eg:http://quan.cms/api/backend/admin/add