Laravel 5 - 嵌套资源索引方法资源 ID



我尝试在 Laravel Restful 控制器上制作一个默认控制器,我被 index 方法和 Nested Resources 阻止了。

我有一个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}是什么意思?photo_id是否在网址中?喜欢photos/1/comments

这是我如何做到的,它的工作原理是:

路线.php

Route::resource('users.stuff' ,'StuffController');

东西控制器.php

public function index($uid, Request $request)
{
    //$uid contains the user id that is in the URL
    User::find($uid)->doSomeStuff();
    dd($uid);

最新更新