I've been working with Lumen, and I've noticed a convenient feature where I can ignore some route parameters, and the parameter will automatically match the name of the argument. However, in Laravel, it seems like this option is not available by default.
eg:
Route::get('{category_id}/system/batches/{batch_id}', 'CirculyDb\Settings\BatchSettingController@show');
// controlloer method, category_id can be ignored
public function show($batch_id): JsonResponse
Is there a way to achieve similar behavior in Laravel, where I can ignore specific route parameters and have them automatically match the corresponding argument name?
This does not seem to be possible because the routing code is completely different.
You can achieve something similar to what you need by using the route method on the request:
Route::get('{category_id}/system/batches/{batch_id}', 'CirculyDb\Settings\BatchSettingController@show');
// controller method, category_id can be ignored
public function show(): JsonResponse {
request()->route('batch_id');
}
As an aside Lumen uses Container::call
to call controller methods which will do dependency injection but also match named parameters, while laravel does a simple method invocation, so presumably if you implement your own ControllerDispatcher
you can possibly emulate this behaviour. Original source for that is here. I briefly tried but it's a bit too complex to do with reasonable effort.