jungmyung
jungmyung

Reputation: 319

How to send update data id to controller in Laravel5.2

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']);

Upvotes: 0

Views: 69

Answers (1)

Filip Koblański
Filip Koblański

Reputation: 9988

You need to define it in your routes like this:

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

by adding {id} into it.

Upvotes: 1

Related Questions