laravel中间件都有哪些

中间件有:1、Authenticate;2、CheckForMaintenanceMode;3、EncryptCookies;4、RedirectIfAuthenticated;5、TrimStrings;6、TrustProxies等等。

laravel中间件都有哪些

本教程操作环境:windows7系统、Laravel6版、Dell G3电脑。

Laravel自带的中间件

Laravel 自带了一些中间件,包括身份验证、CSRF 保护等。Laravel 具体启用了哪些中间件,可通过 appHttpKernel.php 文件查看。对于以 AppHttpMiddleware 开头的中间件(位于 app/Http/Middleware 目录)是我们可以对其行为进行定制的中间件。

Authenticate 中间件

源文件:appHttpMiddlewareHttpMiddlewareAuthenticate.php

expectsJson()) {            return route('login');        }    }}

作用:

用户身份验证。可修改 redirectTo 方法,返回未经身份验证的用户应该重定向到的路径。

CheckForMaintenanceMode 中间件

源文件 :appHttpMiddlewareCheckForMaintenanceMode.php

<?phpnamespace AppHttpMiddleware;use IlluminateFoundationHttpMiddlewareCheckForMaintenanceMode as Middleware;class CheckForMaintenanceMode extends Middleware{    /**     * The URIs that should be reachable while maintenance mode is enabled.     *     * @var array     */    protected $except = [        //    ];}

作用:

检测项目是否处于 维护模式。可通过 $except 数组属性设置在维护模式下仍能访问的网址。

EncryptCookies 中间件

源文件:appHttpMiddlewareEncryptCookies.php

<?phpnamespace AppHttpMiddleware;use IlluminateCookieMiddlewareEncryptCookies as Middleware;class EncryptCookies extends Middleware{    /**     * The names of the cookies that should not be encrypted.     *     * @var array     */    protected $except = [        //    ];}

作用

对 Cookie 进行加解密处理与验证。可通过 $except 数组属性设置不做加密处理的 cookie。

RedirectIfAuthenticated 中间件

v4.6科美智能企业网站管理系统专业版(带手机版) v4.6科美智能企业网站管理系统专业版(带手机版)

科美智能企业网站管理系统专业版是以asp+access进行开发的企业网站系统,软件还包含了全站生成静态页面的功能。特别提醒:1.切勿用那些调试软件调试(比如:aspweb、NETBOX、小旋风等),如果您想本地运行源码,请参照赠品中的环境搭建教程。2.切勿用免费空间(试用空间可以),因为免费空间一般没有写入权限,且会挂广告破坏程序,程序无法正常运行。3.后台添加内容后,如果有的前台

v4.6科美智能企业网站管理系统专业版(带手机版) 108 查看详情 v4.6科美智能企业网站管理系统专业版(带手机版)

源文件:appHttpMiddlewareRedirectIfAuthenticated.php

check()) {            return redirect('/home');        }        return $next($request);    }}

作用:

当请求页是 注册、登录、忘记密码 时,检测用户是否已经登录,如果已经登录,那么就重定向到首页,如果没有就打开相应界面。可以在 handle 方法中定制重定向到的路径。

TrimStrings 中间件

源文件:appHttpMiddlewareTrimStrings.php

<?phpnamespace AppHttpMiddleware;use IlluminateFoundationHttpMiddlewareTrimStrings as Middleware;class TrimStrings extends Middleware{    /**     * The names of the attributes that should not be trimmed.     *     * @var array     */    protected $except = [        'password',        'password_confirmation',    ];}

作用:

对请求参数内容进行 前后空白字符清理。可通过 $except 数组属性设置不做处理的参数。

TrustProxies 中间件

源文件:appHttpMiddlewareTrustProxies.php

<?phpnamespace AppHttpMiddleware;use IlluminateHttpRequest;use FideloperProxyTrustProxies as Middleware;class TrustProxies extends Middleware{    /**     * The trusted proxies for this application.     *     * @var array|string     */    protected $proxies;    /**     * The headers that should be used to detect proxies.     *     * @var int     */    protected $headers = Request::HEADER_X_FORWARDED_ALL;}

作用:

配置可信代理。可通过 $proxies 属性设置可信代理列表,$headers 属性设置用来检测代理的 HTTP 头字段。

VerifyCsrfToken 中间件

源文件:appHttpMiddlewareVerifyCsrfToken.php

<?phpnamespace AppHttpMiddleware;use IlluminateFoundationHttpMiddlewareVerifyCsrfToken as Middleware;class VerifyCsrfToken extends Middleware{    /**     * Indicates whether the XSRF-TOKEN cookie should be set on the response.     *     * @var bool     */    protected $addHttpCookie = true;    /**     * The URIs that should be excluded from CSRF verification.     *     * @var array     */    protected $except = [        //    ];}

作用:

验证请求里的令牌是否与存储在会话中令牌匹配。可通过 $except 数组属性设置不做 CSRF 验证的网址。

相关推荐:最新的五个Laravel视频教程

以上就是laravel中间件都有哪些的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/727908.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年11月25日 10:22:40
下一篇 2025年11月25日 10:23:58

相关推荐

发表回复

登录后才能评论
关注微信