Accessing the URL parameter in the route prefix from middleware
I am trying to access the route prefix parameter from my middleware.
Given this URL: http://www.example.com/api/v1/campaign/40/status
and the following route:
Route::group( [
'prefix' => 'api/v1'
], function()
{
Route::group( [
'prefix' => 'campaign/{campaign}',
'where' => [ 'campaign' => '[0-9]+' ],
'middleware' => [
'inject_campaign'
]
], function()
{
Route::get( 'status', 'CampaignController@getStatus' );
} );
} );
How do I access the campaign parameter (40 in the example url) from my add_campaign middleware? The middleware is working fine for me, but cannot work out how to access the parameter.
A call $request->segments()
in my middleware gives me part of the route, but that seems like a fragile way to access data. What if the route changes?
+3
source to share