2

I'm applying Litespeed cache on our website and I need to use parameter value from route when calling lstag middleware.

I've already tried using

Route::getCurrentRoute()->parameter('slug');
Request->route()->paremeter('slug');
Request::route('route.name')->parameter('slug');

and everything else I could find on the Internet, but nothing was working. It just throwed error In web.php line 103:

Call to a member function parameter() on null

My full code for route is

Route::get('serialy/{slug}', 'SerialsController@show')->name('serials.show')->middleware('lstag:serial.' . Route::getCurrentRoute()->parameter('slug'));

I expect that I can use a value of parameter when calling a route middleware (lstag), but I can't find any way to do it. Is it even possible?

lagbox
  • 48,571
  • 8
  • 72
  • 83
djlimix
  • 59
  • 10
  • 1
    The routes are registered before the route is dispatched ... there is no route handled at the time the routes are registered (there is no current route) ... if you need the value of a parameter you need to get it in the middleware – lagbox Oct 09 '19 at 20:58

1 Answers1

1

As already mentioned by @lagbox, the above won't really be possible.

However, you can use the lstags middleware in the controller __construct() ( https://laravel.com/docs/6.x/controllers#controller-middleware ).

There you should have the information available that you need to build up your X-LiteSpeed-Tag header as you wish.

LucasRolff
  • 1,228
  • 3
  • 11
  • 20