传递给App \ Http \ Controllers \ NoticeCommentController :: destroy()的参数1必须是App \ NoticeComment的实例,给定App \ Notice的实例

时间:2019-03-26 05:04:57

标签: reactjs laravel

我在laravel中有一个问题要看:

enter image description here

请帮助我。

NoticeCommentController.php

public function destroy(NoticeComment $noticeComment)
{
    $noticeComment->delete();
}

但这不起作用。

  

传递给App \ Http \ Controllers \ NoticeCommentController :: destroy()的参数1必须是App \ NoticeComment的实例,给出了App \ Notice的实例

什么是问题..?

我在github中的代码:https://github.com/jonsoku/homepage2

1 个答案:

答案 0 :(得分:3)

更改为此

public function destroy(Notice $notice, NoticeComment $noticeComment)
{
    $noticeComment->delete();
}

说明

当您定义这样的嵌套资源时

Route::resource('notices.noticeComments', 'NoticeCommentController');

您的路线将是这样

notices/{notice}/noticeComments/{noticeComment}

因此,您的第一个参数将是Notice,第二个参数是NoticeComment,希望对您有所帮助。

您可以在此处阅读更多内容 https://laravel.com/docs/5.1/controllers#restful-nested-resources