я хочу вставить данные в БД, но показ неопределенной ошибки индекса - PullRequest
0 голосов
/ 06 марта 2020

Я хочу восстановить ввод, чтобы вставить его в Мою БД, но показывается неопределенная ошибка индекса, но я уверен, что индекс совпадает !!!!!
это мой 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);


     }

1 Ответ

0 голосов
/ 06 марта 2020

На самом деле я немного запутался с кодом. Но я думаю, что вы хотите сохранить в $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();
}
...