Search code examples
phplaravellitespeed

How to pass route parameter value to middleware definition for route?


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?


Solution

  • 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.