Laravel - Can I pass a parameter with apiResource to the index function in the controller?

泄露秘密 提交于 2019-12-25 00:35:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!