让我用一个真实的例子来重新表述这个问题。
我有中间件
<?php
namespace App\Http\Middleware;
use Closure;
class EmailIsVerifiedOverride
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// TODO: Добавить проверку на верифицированность профиля.
return $next($request);
}
}
在 Laravel 6.0 中(下面不知道)有 Auth
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class
我通过创建一个新层并修改内核的行为来覆盖这个组件:
'verified.default' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'verified' => \App\Http\Middleware\EmailIsVerifiedOverride::class,
实际上,我想在我的覆盖中使用中间件并重新定义它。
<?php
namespace App\Http\Middleware;
use Closure;
class EmailIsVerifiedOverride
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$requireVerified = true;
if ($requireVerified)
$this->middleware('verified.default');
return $next($request);
}
}
喜欢这个解决方案。
类 EmailIsVerifiedOverride: