douwen0647
2016-10-11 07:18
浏览 65
已采纳

如何在Laravel5.2中将更新数据id发送到控制器

I want send $comment->id to Controller updateComment method, and just update one column(comment)

Here's my code, It brings error like this :ErrorException in BoardController.php line 153: Missing argument 1 for App\Http\Controllers\BoardController::updateComment()

View

<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>

Controller

public function updateComment($id) {

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

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

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

    return redirect()->back();
}

Route

Route::match(['put', 'patch'], 'comment', ['as'=>'comment.update', 'uses'=>'BoardController@updateComment']);

图片转代码服务由CSDN问答提供 功能建议

我想将$ comment-&gt; id发送到Controller updateComment方法, 只需更新一列(注释)< / p>

这是我的代码,它带来如下错误:BoardController.php第153行中的ErrorException: 为App \ Http \ Controllers \ BoardController :: updateComment()</ p>提供参数1 n

查看</ p>

 &lt; form method =“post”action =“{{route('comment.update',$ comment-&gt; id)}  }“&gt; 
&lt; input type =”hidden“name =”_ method“value =”put“&gt; 
&lt; input type =”hidden“name =”_ token“value =”{{csrf_token()}}“  &gt; 
&lt; textarea name =“comment”&gt;'+ beforeComment +'&lt; / textarea&gt; 
&lt; input type =“submit”value =“등록”&gt; 
&lt; / form&gt; 
 </ code>  </ pre> 
 
 

控制器</ p>

  public function updateComment($ id){
 
 $ comment = comment :: findOrFail($ id);  
 
 $ body = Request :: input('comment'); 
 
 $ comment-&gt; update(['comment'=&gt; $ body]); 
 
返回redirect() - &gt  ; back(); 
} 
 </ code> </ pre> 
 
 

路线</ p> <pr e> Route :: match(['put','patch'],'comment',['as'=&gt;'comment.update','uses'=&gt;'BoardController @ updateComment']) ; </ code> </ pre> </ div>

1条回答 默认 最新

相关推荐 更多相似问题