Laravel 框架指定路由關閉 csrf
阿新 • • 發佈:2019-01-31
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier {
//不過濾的 url
protected $except=array(
'weixin'
);
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$_url=$request->decodedPath();
if(in_array($_url,$this->except)){
unset($_url);
// 禁用CSRF
return $next($request);
}else{
unset($_url);
// 使用CSRF
return parent::handle($request, $next);
}
}
}