1 - 你的路由将使用来自App\Providers\RouteServiceProvider 的中间件。见:
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
您编写的每个中间件都将按照您定义的顺序执行。如果一个中间件发生故障,$next($request); 将不会被调用。所以下一个中间件不会被激活。
2- 这些auth:web 和auth:custom 中间件是“auth 中间件”调用,但参数不同。 : 之后的所有内容都作为参数发送到中间件的处理方法。
auth 中间件定义在App\Http\Kernel 类下$routeMiddleware var:
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
这里是handle 方法:
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string[] ...$guards
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
*/
public function handle($request, Closure $next, ...$guards)
{
$this->authenticate($guards);
return $next($request);
}
您的 'web' 或 'custom' 参数转到 ...$guards 参数。
顺便说一句,没有预定义的“自定义”防护。您必须编写自己的自定义守卫并在config/auth.php、guards 数组下定义它:
'guards' => [
'web' => [ // This is the web guard (auth:web)
'driver' => 'session',
'provider' => 'users',
],
'api' => [ // and this the api guard (auth:api)
'driver' => 'token',
'provider' => 'users',
],
],
然后,您可以期望 laravel auth 中间件使用您的自定义防护(如 auth:custom 或 auth:acme)进行身份验证。