站長資訊網(wǎng)
最全最豐富的資訊網(wǎng)站

laravel中間件都有哪些

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

laravel中間件都有哪些

本教程操作環(huán)境:windows7系統(tǒng)、Laravel6版、Dell G3電腦。

Laravel自帶的中間件

Laravel 自帶了一些中間件,包括身份驗證、CSRF 保護等。Laravel 具體啟用了哪些中間件,可通過 appHttpKernel.php 文件查看。對于以 AppHttpMiddleware 開頭的中間件(位于 app/Http/Middleware 目錄)是我們可以對其行為進行定制的中間件。

Authenticate 中間件

源文件:appHttpMiddlewareHttpMiddlewareAuthenticate.php

<?php namespace AppHttpMiddleware; use IlluminateAuthMiddlewareAuthenticate as Middleware; class Authenticate extends Middleware {     /**      * Get the path the user should be redirected to when they are not authenticated.      *      * @param  IlluminateHttpRequest  $request      * @return string      */     protected function redirectTo($request)     {         if (! $request->expectsJson()) {             return route('login');         }     } }

作用:

用戶身份驗證。可修改 redirectTo 方法,返回未經(jīng)身份驗證的用戶應該重定向到的路徑。

CheckForMaintenanceMode 中間件

源文件 :appHttpMiddlewareCheckForMaintenanceMode.php

<?php namespace 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 數(shù)組屬性設置在維護模式下仍能訪問的網(wǎng)址。

EncryptCookies 中間件

源文件:appHttpMiddlewareEncryptCookies.php

<?php namespace 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 數(shù)組屬性設置不做加密處理的 cookie。

RedirectIfAuthenticated 中間件

源文件:appHttpMiddlewareRedirectIfAuthenticated.php

<?php namespace AppHttpMiddleware; use Closure; use IlluminateSupportFacadesAuth; class RedirectIfAuthenticated {     /**      * Handle an incoming request.      *      * @param  IlluminateHttpRequest  $request      * @param  Closure  $next      * @param  string|null  $guard      * @return mixed      */     public function handle($request, Closure $next, $guard = null)     {         if (Auth::guard($guard)->check()) {             return redirect('/home');         }         return $next($request);     } }

作用:

當請求頁是 注冊、登錄、忘記密碼 時,檢測用戶是否已經(jīng)登錄,如果已經(jīng)登錄,那么就重定向到首頁,如果沒有就打開相應界面。可以在 handle 方法中定制重定向到的路徑。

TrimStrings 中間件

源文件:appHttpMiddlewareTrimStrings.php

<?php namespace 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',     ]; }

作用:

對請求參數(shù)內(nèi)容進行 前后空白字符清理。可通過 $except 數(shù)組屬性設置不做處理的參數(shù)。

TrustProxies 中間件

源文件:appHttpMiddlewareTrustProxies.php

<?php namespace 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

<?php namespace 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 數(shù)組屬性設置不做 CSRF 驗證的網(wǎng)址。

贊(0)
分享到: 更多 (0)
網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號
国产精品jizz观看| 亚洲av永久无码精品秋霞电影秋| 精品国产呦系列在线观看免费| 日韩精品在线免费观看| 国产精品美女久久久浪潮av| 亚洲欧美综合精品成人导航| 精品成在人线AV无码免费看| 久久精品aⅴ无码中文字字幕不卡| 国产成人无码精品一区二区三区| 国产AV午夜精品一区二区三| 久久久久久国产精品美女| 国产精品哟女在线观看| 国产成人无码精品久久久免费 | 久久久这里只有精品加勒比| 亚洲国产精品成人精品软件| 精品永久久福利一区二区| 99精品视频在线免费观看| 伊人久久精品线影院| 亚洲嫩草影院久久精品| 人妻熟妇乱又伦精品视频| 青青草原精品99久久精品66| 久久久精品免费视频| 无码精品久久久天天影视| 夜色www国产精品资源站| 亚洲AV日韩精品久久久久久| 久久99久久99精品| 亚洲精品国产成人专区| 99久久er热在这里只有精品99| 久久精品国产第一区二区三区| 99久久国产综合精品1尤物| 亚洲精品在线免费观看| 精品成人乱色一区二区| 亚洲精品日韩专区silk| 精品国产sm捆绑最大网免费站| 精品91自产拍在线| 国内揄拍国内精品对白86| 成人国内精品视频在线观看| 国产精品嫩草影院线路| 在线日韩日本国产亚洲| 日韩亚洲精品福利| 久久久精品视频免费观看|