Laravel 5 - Nest Resource 索引方法资源ID
Laravel 5 - Nest Resource index method resource ID
我尝试创建一个基于 Laravel Restful Controller 的默认控制器,但我使用 Nested Resources
的 index
方法阻止了。
我有一条路线 Route::resource('photos.comments', 'DefaultController');
,我需要在我的 index
方法中获取 photo_id
。但是这么费,我只得到{photos}
.
public function index(Request $request)
{
// $request->route('photos) => {photos}
}
或
public function index(Request $request, $photosId)
{
// photosId => {photos}
}
我错过了什么?
谢谢
显然你做对了。你说你得到 {photos}
是什么意思? URL中的photo_id
吗?喜欢 photos/1/comments
?
以下是我的做法和效果:
route.php
Route::resource('users.stuff' ,'StuffController');
StuffController.php
public function index($uid, Request $request)
{
//$uid contains the user id that is in the URL
User::find($uid)->doSomeStuff();
dd($uid);
我尝试创建一个基于 Laravel Restful Controller 的默认控制器,但我使用 Nested Resources
的 index
方法阻止了。
我有一条路线 Route::resource('photos.comments', 'DefaultController');
,我需要在我的 index
方法中获取 photo_id
。但是这么费,我只得到{photos}
.
public function index(Request $request)
{
// $request->route('photos) => {photos}
}
或
public function index(Request $request, $photosId)
{
// photosId => {photos}
}
我错过了什么?
谢谢
显然你做对了。你说你得到 {photos}
是什么意思? URL中的photo_id
吗?喜欢 photos/1/comments
?
以下是我的做法和效果:
route.php
Route::resource('users.stuff' ,'StuffController');
StuffController.php
public function index($uid, Request $request)
{
//$uid contains the user id that is in the URL
User::find($uid)->doSomeStuff();
dd($uid);