简体   繁体   English

如何将自定义中间件添加到 Laravel Nova

[英]How to add custom middleware to Laravel Nova

I am not 100% expert with Laravel routes, so I am finding some issues trying to accomplish the following:我不是 Laravel 路线的 100% 专家,所以我发现一些问题试图完成以下任务:

  • on each an every Nova page requested, I need to first verify that a token is obtained and valid on an external service (it expires every 30').在每个请求的每个 Nova 页面上,我需要首先验证一个令牌是否已获得并且在外部服务上有效(它每 30' 过期)。
  • I have a controller handle managing that and working fine.我有一个 controller 手柄管理它并且工作正常。 My problem is that I don't hit the nail with adding this verification to a middleware.我的问题是我没有把这个验证添加到中间件中。
  • In other words, before displaying any Nova view, I need to check that this token is not expired.换句话说,在显示任何 Nova 视图之前,我需要检查此令牌是否未过期。 If it is, I post a call and refresh it.如果是,我会发布一个电话并刷新它。

I've googled around and found no similar question/issue.我用谷歌搜索并没有发现类似的问题/问题。 Anyone can give me an enlighting example?谁能给我一个启发性的例子?

Thanks in advance.提前致谢。

I found the place while looking at another post here.我在这里看另一个帖子时找到了这个地方。 What I was missing was to declare my token validator class in config/nova.php我缺少的是在 config/nova.php 中声明我的令牌验证器 class

Here:这里:

`/*
|--------------------------------------------------------------------------
| Nova Route Middleware
|--------------------------------------------------------------------------
|
| These middleware will be assigned to every Nova route, giving you the
| chance to add your own middleware to this stack or override any of
| the existing middleware. Or, you can just stick with this stack.
|
*/

'middleware' => [
    'web',
    Authenticate::class,
    DispatchServingNovaEvent::class,
    BootTools::class,
    Authorize::class,
    HereShouldGoMyClass::class,
],`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM