问题
Is there a way to pass a parameter into an apiResource route? I want only the index to take an userId. Adding {id} to the route does not seem to help. I looked at the laravel website but couldn't find anything about adding custom parameters.
I had a previous post about this but to make the question more clear I made a new post. I'll delete the previous post later today.
https://laravel.com/docs/5.7/controllers#resource-controllers
Route::apiResource('campaigns', 'CampaignController');
回答1:
No theres no way to do thats but you can make this, and is the same.
Route::apiResource('campaigns', 'CampaignController',['except' => 'index']);
Route::get('campaigns/{id}', [
'as' => 'campaigns.index',
'uses' => 'CampaignController@index'
]);
来源:https://stackoverflow.com/questions/58344315/laravel-can-i-pass-a-parameter-with-apiresource-to-the-index-function-in-the-c