Laravel内核加载动态中间件阵列



想要编辑我的内核.php文件并在应用程序中就地禁用了一些中间件(我希望我的标头响应很快,这是我的堆栈主题(

我有一些想法,但我不知道下一步是什么:

class Kernel extends HttpKernel
{
public function __construct(Application $app, Router $router)
{
$url = IlluminateHttpRequest::capture()->url();
if($url == 'http://autoservie.test/save'){
//HERE i want set  protected $middlewareGroup and remove session 
middleware from 'web'
}else{
// HERE set another protected $middlewareGroup
}
parent::__construct($app, $router);
}
protected $middlewareGroups = [
'web' => [
AppHttpMiddlewareEncryptCookies::class,
IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
IlluminateSessionMiddlewareStartSession::class,
// IlluminateSessionMiddlewareAuthenticateSession::class,
IlluminateViewMiddlewareShareErrorsFromSession::class,
AppHttpMiddlewareVerifyCsrfToken::class,
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];

问题是,如何在构造函数中设置动态保护$middlewareGroups数组?还是有其他解决方案?

你可以做类似的事情

$index = array_search(IlluminateSessionMiddlewareStartSession::class, $middlewareGroups['web']);
unset($middlewareGroups['web'][$index]);

最新更新