Laravel 5.2.x禁用特定的中间件 [英] Laravel 5.2.x disable specific middleware
本文介绍了Laravel 5.2.x禁用特定的中间件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在不禁用所有中间件的情况下禁用特定的中间件?
Is it possible to disable a specific middleware without disabling all middleware?
我将在运行测试时使用它,所以我不想定义中间件组,然后将它们分配给我的路由.
I will use it when running tests, so I don't want to define middleware groups and then assign them to my routes.
$this->withoutMiddleware(); // <-- This will prevent all middleware
$this->withoutMiddleware('web'); // <-- What I want is something like this
推荐答案
我有一个替代解决方案,您可以根据您的环境在受影响的中间件中添加一个条件:
I have an alternative solution, you could add a condition in your impacted middleware according to your environnement :
public function handle($request, Closure $next)
{
if (App::environment('testing')) {
return $next($request);
}
// Your middleware logic
return $next($request);
}
这篇关于Laravel 5.2.x禁用特定的中间件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文