Temporarily disable / bypass Middleware

大憨熊 提交于 2019-12-05 08:02:21

Apparently with the release of Laravel 5.1 yesterday a disableMiddleware() method was added to the TestCase class, which now does exactly what I wanted.

Problem solved. :)

The only answer that I could come up with was to put a bypass in the actual middleware itself. For example:

public function handle($request, Closure $next)
{
    // Don't validate authentication when testing.
    if (env('APP_ENV') === 'testing') {
        return $next($request);
    }
    // ... continue on to process the request
}

I don't like the idea of making the middleware dependent on the app environment but I couldn't see any other options.

Here's a package that I worked on after having the same issue.

https://github.com/moon0326/FakeMiddleware

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!