SQLSTATE[23502]:非空违规:在 laravel 中更新注释时出现 7 错误

SQLSTATE[23502]: Not null violation: 7 ERROR when update comment in laravel

我想更新 Laravel 中的评论。

<div class="edit-input" id="edit{{$comment->id}}">
   <input type="text" name="edit_comment" class="form-control">
   <div class="input-group-append">
       <a href="{{ route('review-edit', [ 'id' => $comment->id]) }}" class="btn btn-primary">OK</a>
       <button class="btn btn-danger" id="editCancel" type="button">Cancel</button>
   </div>
</div>

这是我的路线:

Route::get('review-edit/{id}', 'CommentController@editComment')->name('review-edit');

和评论控制器:

public function editComment(Request $request, $id)
    {

        $updateComment = Comment::findOrFail($id);
        $updateComment->user_id = Auth::id();
        $updateComment->comment = $request->edit_comment;
        $updateComment->save();
        return back();

    }

当我尝试更新评论时,我收到一条错误提示

SQLSTATE[23502]: Not null violation: 7

dd($request->edit_comment) 也给出空值。我在这里忽略了什么?

试试这个 你 edit_comment 应该在表单内然后只有你可以将数据发送到控制器

<form action="{{ route('review-edit', [ 'id' => $comment->id]) }}" method="get">
    <div class="edit-input" id="edit{{$comment->id}}">
       <input type="text" name="edit_comment" class="form-control">
       <div class="input-group-append">
           <button class="btn btn-info" type="submit">OK</button>
           <button class="btn btn-danger" id="editCancel" type="button">Cancel</button>
       </div>
    </div>
</form>

试试这个 dd($request->edit_comment);

 <form action="{{ route('review-edit', [ 'id' => $comment->id]) }}" method="get">
    <div class="edit-input" id="edit{{$comment->id}}">
       <input type="text" name="edit_comment" class="form-control">
       <div class="input-group-append">
           <button class="btn btn-info" type="submit">OK</button>
           <button class="btn btn-danger" id="editCancel" type="button">Cancel</button>
       </div>
    </div>
    </form>