未定义变量:Laravel中的visiteur

问题描述 投票:0回答:1

[Helloo,我想在会话中添加注释,其中显示使用添加的患者的姓名,并使用session,所以出现此错误:Undefined variable: visiteur

这是commentcontroller.php

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

     return back()->with(['visiteur'=>$visitor]);
}
}

这是视图:show.blade.php

 <div class="card-body" >
  @foreach ($showme->comments as $comment)
    <blockquote class="blockquote mb-0">
      <p style="font-size:15px;">{{$comment->body}}</p>
        @foreach ($visiteur as $viis)
        @if ($comment->patient_id == $viis->id)
         <p> {{$comment->patient_id}}</p>
        @endif
        @endforeach
      <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');

这是患者控制者:

public function welcome(Request $request)
    {
        $request->validate([
            'mail' => 'required|email',
            'mdp' => 'required',
        ]);

        // since email is unique. no need to grab all data
        $patient = patient::where('Login', $request->input('mail'))->first();


        // if patient exists
        if ($patient) {
            // check hashed password
            // assuming $patient->Password hashed
            if (Hash::check($request->input('mdp'), $patient->Password)) {
                //session 
                $request->session()->put('patient_id', $patient->Nom);
                $request->session()->put('log_in', true);
                return redirect ('index');
            }
        }
        return back()->withErrors([
            'message' => 'Emails or password not correct!',
        ]);
    }

我想显示添加评论的用户名,但他只显示ID

php laravel session
1个回答
1
投票

应该是

return back()->with(['visiteur', $visitor]);
© www.soinside.com 2019 - 2024. All rights reserved.