2016-10-11 107 views
0

我想送$ comment-> id來控制updateComment方法, ,只是更新一列(評論)如何更新數據ID發送到控制器Laravel5.2

這裏是我的代碼,它帶來的錯誤是這樣:ErrorException在BoardController.php線153: 缺少參數1爲App \ HTTP \控制器\ BoardController :: updateComment()

查看

<form method="post" action="{{route('comment.update', $comment->id)}}"> 
<input type="hidden" name="_method" value="put"> 
<input type="hidden" name="_token" value="{{ csrf_token() }}"> 
<textarea name="comment">'+beforeComment+'</textarea> 
<input type="submit" value="등록"> 
</form> 

控制器

public function updateComment($id) { 

    $comment = comment::findOrFail($id); 

    $body = Request::input('comment'); 

    $comment->update(['comment' => $body]); 

    return redirect()->back(); 
} 

路線

Route::match(['put', 'patch'], 'comment', ['as'=>'comment.update', 'uses'=>'[email protected]']); 

回答

1

你需要在你的路由來定義它是這樣的:

Route::match(['put', 'patch'], 'comment/{id}', ['as'=>'comment.update', 'uses'=>'[email protected]']); 

加入{id}進去。

相關問題