php - Laravel 5.4 路由问题
ringa_lee
ringa_lee 2017-04-11 10:39:02
[PHP讨论组]

Laravel 5.4 在api.php 中注册路由不生效,在web.php 中注册可以。请教下谁遇到过这样的问题吗

ringa_lee
ringa_lee

ringa_lee

全部回复(2)
迷茫

首先你可以看一下 app/Http/Kernel.php 这个文件,都就可以看出来api.php 和web.php的区别
protected $middlewareGroups = [

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

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

api.php 配合Laravel passport来使用提供 API 服务,所有路由在访问时都有一个/api的前缀,通常是做前后端完全分离时给前端ajax使用的

黄舟

主要是定义在 \App\Providers\RouteServiceProvider

    protected function mapApiRoutes()
    {
        Route::group([
            'middleware' => 'api',
            'namespace' => $this->namespace,
            'prefix' => 'api',
        ], function ($router) {
            require base_path('routes/api.php');
        });
    }

api.php 的路由都上了 /api 前缀。
而 middleware 是定义在 \App\Http\Kernel 中的 $middlewareGroups

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号