Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument 1 passed to App\Http\Controllers\NoticeCommentController::destroy() must be an instance of App\NoticeComment, instance of App\Notice given

Tags:

laravel

I have a problem in laravel to see this:

enter image description here

help me please.

NoticeCommentController.php:

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

but this is not working..

Argument 1 passed to App\Http\Controllers\NoticeCommentController::destroy() must be an instance of App\NoticeComment, instance of App\Notice given

what is problem..?

my code in github : https://github.com/jonsoku/homepage2

like image 335
JLtokyo Avatar asked Dec 07 '25 19:12

JLtokyo


1 Answers

Change to this

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

Explain

when you defined nested resource like this

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

your route going to be something like this

notices/{notice}/noticeComments/{noticeComment}

So your first parameter is going to be Notice and second param is NoticeComment, hope it help.

You can read more here https://laravel.com/docs/5.1/controllers#restful-nested-resources

like image 107
Kyaw Kyaw Soe Avatar answered Dec 09 '25 20:12

Kyaw Kyaw Soe