'return $next($request)' 在 Laravel 中间件中做了什么?

What does 'return $next($request)' do in Laravel middleware?

请尊重我是编程新手 Laravel,所以这个问题对你们大多数人来说可能有点奇怪。
但我认为这就是 Whosebug 的用途,所以:

当我使用命令 php artisan make:middleware setLocale 创建一个新的中间件时,已经有 handle-函数,其中包含以下代码:

return $next($request);

我想知道这条线到底是做什么的。

这在文档中有解释:

To pass the request deeper into the application (allowing the middleware to "pass"), call the $next callback with the $request.

It's best to envision middleware as a series of "layers" HTTP requests must pass through before they hit your application. Each layer can examine the request and even reject it entirely.

https://laravel.com/docs/5.8/middleware#defining-middleware

$next($request) 只是将请求传递给下一个处理程序。 假设您添加了一个用于检查年龄限制的中间件。

public function handle($request, Closure $next)
{
    if ($request->age <= 18) {
        return redirect('home');
    }

    return $next($request);
}

当年龄小于 18 岁时,它将重定向到家,但是当请求通过条件时,应该如何处理请求?它会将它传递给下一个 handler.Probably 到注册用户方法或任何视图。