简体   繁体   中英

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:

  • 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').
  • I have a controller handle managing that and working fine. 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. 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

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,
],`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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