【问题标题】:How to send update data id to controller in Laravel5.2如何在 Laravel5.2 中向控制器发送更新数据 id
【发布时间】:2017-02-19 16:41:40
【问题描述】:

我想将 $comment->id 发送到控制器的 updateComment 方法, 只需更新一列(评论)

这是我的代码,它在 BoardController.php 第 153 行带来了这样的错误:ErrorException: App\Http\Controllers\BoardController::updateComment() 缺少参数 1

查看

<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'=>'BoardController@updateComment']);

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    你需要像这样在你的路由中定义它:

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

    在其中添加{id}

    【讨论】:

      猜你喜欢
      • 2017-05-02
      • 1970-01-01
      • 2014-02-07
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      相关资源
      最近更新 更多