Laravel 默认 Middleware 问题

route.php 文件如下


Route::group(['middleware' => ['guest']], function () {
    Route::get('/', ['as' => 'homepage', 'uses' => 'HomeController@index']);
});

用php artisan route:list,看到的如下


+--------+----------+-----+----------+-------------------------------------------+--------------------------------------------+
| Domain | Method   | URI | Name     | Action                                    | Middleware                                 |
+--------+----------+-----+----------+-------------------------------------------+--------------------------------------------+
|        | GET|HEAD | /   | homepage | App\Http\Controllers\HomeController@index | web,guest,App\Http\Middleware\Authenticate |
+--------+----------+-----+----------+-------------------------------------------+--------------------------------------------+

这个App\Http\Middleware\Authenticate Middleware是哪来呢?
框架代码是另外一个项目copy过来的,不知道哪里被修改了..

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 4

@lx1036 Kernel.php,看上去好像是默认的


    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    ];
    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,
        ],

        'api' => [
            'throttle:60,1',
        ],
    ];
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    ];
7年前 评论

看一看 HomeController__construct 方法里面有没有添加中间件

7年前 评论

@young 果然。。。这里加了个middleware..谢谢

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!