【问题标题】:i want to insert data to DB but undefined index error show我想将数据插入数据库但未定义的索引错误显示
【发布时间】:2020-06-18 15:23:52
【问题描述】:

我想恢复输入以将其插入到我的数据库中,但显示未定义的索引错误,但我确定索引是相似的!!!!!!
这是我的 ProjectDetail.vue 表单:

    <form type="post"  @submit.prevent="ajouterCommentaireReponse(comment.id)"  v- 
        bind:id="comment.id " class="d-none">

   <div class="input-group input-group-sm mt-2 ml-2">
    <input class="form-control form-control-sm" name="replycomment"  
    type="text"  placeholder="commenter.." style="width:450px;" >

     <div class="input-group-append">
     <button type="submit" class="btn btn-success">Commenter</button>
      </div>
    </div>
   </form>

这是控制器功能:

   public function storereply(Request $request,$key){
    $data =$request->all();
   $commentaire=Commentaire::find($key);
    $commentairereply =new Commentaire;
    $commentairereply->user_id= auth()->user()->id;
    $commentairereply->body = $data['replycomment'];
   $commentairereply->comment_user_name=$commentaire->user->name;
   $commentaire->comments()->save($commentairereply);


     }

【问题讨论】:

  • 您是否尝试过dd($data); 以查看replycomment 是否确实作为键之一存在?还可以尝试dd($request-&gt;replycomment) ..
  • 我尝试了 dd($data) 但没有任何反应!!!
  • 他什么都没给我看

标签: laravel vue.js vuejs2 laravel-6


【解决方案1】:

实际上我对代码有点困惑。但我认为你想保存到$commentaire,并且这样做,storereply 函数的最后一行应该是这样的

public function storereply(Request $request,$key){
    $data =$request->all();
    $commentaire=Commentaire::find($key);
    $commentairereply =new Commentaire;
    $commentairereply->user_id= auth()->user()->id;
    $commentairereply->body = $data['replycomment'];
    $commentairereply->comment_user_name=$commentaire->user->name;
    // $commentaire->comments()->save($commentairereply);
    $commentairereply->save();
}

【讨论】:

  • 没有回复评论索引中的问题,他向我显示了未定义索引的错误,但输入的名称和 $data['replycomment'];相似
  • 您检查过模型中的$fillable 吗?通常我有未定义的索引,因为可填充或索引实际上不存在
猜你喜欢
  • 2023-04-11
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
  • 2015-03-22
  • 1970-01-01
  • 2014-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多