Laravel-我可以将带有apiResource的参数传递给控制器​​中的索引函数吗? [英] Laravel - Can I pass a parameter with apiResource to the index function in the controller?

查看:86
本文介绍了Laravel-我可以将带有apiResource的参数传递给控制器​​中的索引函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将参数传递到apiResource路由?我只希望索引采用一个userId.将{id}添加到路由似乎无济于事.我查看了laravel网站,但找不到有关添加自定义参数的任何信息.

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');

推荐答案

没有办法做到这一点,但您可以做到这一点,而且是相同的.

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'
]);

这篇关于Laravel-我可以将带有apiResource的参数传递给控制器​​中的索引函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆