关于laravel中间件

WBOY
Release: 2016-06-06 20:06:41
Original
1287 people have browsed it

定义了一个LoginMiddleware类,handle方法中定义了只允许内网用户方法的规则,当现在所有路由都走这个规则,如果我只想某些路由走这个规则该怎么操作?
谢谢

回复内容:

定义了一个LoginMiddleware类,handle方法中定义了只允许内网用户方法的规则,当现在所有路由都走这个规则,如果我只想某些路由走这个规则该怎么操作?
谢谢

  • 首先需要在 app/Kernel.php 下的 $routeMiddleware 数组内注册此路由,注意是 $routeMiddleware 而不是 $middleware

  • App/routes.php 中定义一个 Group,对此组应用某中间件,如下:

<code>    Route::group(['middleware' => 'auth'], function () {
        //...
    });</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template