The scenario I want to achieve is that I want to access the prefix $fragment
outside the closure.
So this is what I want to achieve:
Route::group([
'prefix' => '{fragment}',
'namespace' => 'AppHttpControllers' . 'V' . '{fragment}',
'middleware' => [
'v' . '{fragment}' . '.myMiddleWare',
],
], function ($pathParam) {
Route::get(
'hello',
function ($fragment) use ($pathParam) {
return response()->json([$pathParam]);
}
);
});
I also thought of doing something like:
request()->getHost()
But it returns null.
So it is quite evident that the variable $fragment
would be accessible inside the endpoint /hello
but it is not accessible outside of it.
Any help would be highly appreciated.
Thanks!