首页 > 解决方案 > 想要显示添加评论的用户名

问题描述

我是 Laravel 的新手,在我的项目中,我想在身份验证后在博客中添加评论,我对此使用会话,所以问题是他不显示用户名!

这是我的控制器评论:

public function store  (blog $getid , Request $request)
{
    $patient_id=$request->session()->get('patient_id');
     comment::create([
        'body' =>request('body'),
        'blog_id'=> $getid->id,
        'patient_id'=>$patient_id
    ]);

     return back();
}

这是 show.blade.php :

 @foreach ($showme->comments as $comment)
    <blockquote class="blockquote mb-0">
      <p style="font-size:15px;">{{$comment->body}}</p>
      <p> {{$comment->patient_id}}</p>

      <footer class="blockquote-footer"> {{$comment->created_at}} <cite title="Source Title"> </cite></footer>


    </blockquote>
    @endforeach
  </div>
  <!-- si le patient est connceter -->
  @if(Session::has('log_in'))
    <div class="card-block">
   <form method="POST" action="/blog/{{$showme->id}}/store" >
   @csrf
   <div class="form-group">
   <label> Commentaire </label> </br>
   <textarea name="body"  rows="3" cols="80" cols="form-control"></textarea> </br>
    </div><div class="form-group">
<button type="submit" class="btn btn-primary"> Ajouter commentaire</button>
</div>
  </form>
</div>
@endif

WEB.PHP

Route::Post('/store' , 'patientcontroller@store');

太感谢了

标签: laravelsessioncomments

解决方案


推荐阅读