php - Access a URL Parameter in a Route Prefix from Middleware -
i struggling access route prefix parameter middleware.
given url: http://www.example.com/api/v1/campaign/40/status, , 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 access campaign parameter (40 in example url) inject_campaign middleware? have middleware running fine cannot work out how access parameter.
calling $request->segments() in middleware gives me parts of route seems fragile way of accessing data. if route changes?
you can using shorter syntax
you can use:
echo $request->route()->campaign; or shorter:
echo $request->campaign;
Comments
Post a Comment