关于laravel中间件

php.cn
Release: 2016-06-06 20:06:41
original
1165 people have browsed it

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

回复内容:

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

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

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

    Route::group(['middleware' => 'auth'], function () {
        //...
    });
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 [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!