猿问

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

我想更新 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]:非空违规:7


dd($request->edit_comment) 也给出 null 。我在这里俯瞰什么?


德玛西亚99
浏览 106回答 2
2回答

拉莫斯之舞

试试这个,你edit_comment应该在表单中,然后只有你可以将数据发送到控制器<form action="{{ route('review-edit', [ 'id' => $comment->id]) }}" method="get">&nbsp; &nbsp; <div class="edit-input" id="edit{{$comment->id}}">&nbsp; &nbsp; &nbsp; &nbsp;<input type="text" name="edit_comment" class="form-control">&nbsp; &nbsp; &nbsp; &nbsp;<div class="input-group-append">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<button class="btn btn-info" type="submit">OK</button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<button class="btn btn-danger" id="editCancel" type="button">Cancel</button>&nbsp; &nbsp; &nbsp; &nbsp;</div>&nbsp; &nbsp; </div></form>

开满天机

试试这个dd($request->edit_comment);&nbsp;<form action="{{ route('review-edit', [ 'id' => $comment->id]) }}" method="get">&nbsp; &nbsp; <div class="edit-input" id="edit{{$comment->id}}">&nbsp; &nbsp; &nbsp; &nbsp;<input type="text" name="edit_comment" class="form-control">&nbsp; &nbsp; &nbsp; &nbsp;<div class="input-group-append">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<button class="btn btn-info" type="submit">OK</button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<button class="btn btn-danger" id="editCancel" type="button">Cancel</button>&nbsp; &nbsp; &nbsp; &nbsp;</div>&nbsp; &nbsp; </div>&nbsp; &nbsp; </form>
随时随地看视频慕课网APP
我要回答