如何从 laravel 中的表单中获取 id

How to take the id from the form in laravel

我想更改 table 中患者的状态,所以当我单击按钮 Accepter 时,每个患者的所有状态都会改变,我该如何解决这个问题?

这是控制器:

public function completedUpdate(Request $request, rendezvous $rdv )
{
        $id=$request->input('id');
        $data = rendezvous::all();
        foreach($data as $rdv) {
            if ( $rdv->Etat_de_rdv == 'en_attente' )
            {
            DB::table('rdv')->where('Etat_de_rdv','en_attente')->update(['Etat_de_rdv' => 'Accepter']);
            }

           elseif ( $rdv->Etat_de_rdv == 'Accepter' ) {

            DB::table('rdv')->where('Etat_de_rdv','Accepter')->update(['Etat_de_rdv' => 'Pas disponible']);
           } 

           elseif ( $rdv->Etat_de_rdv == 'Pas disponible' ) 
           {
            DB::table('rdv')->where('Etat_de_rdv','Pas disponible')->update(['Etat_de_rdv' => 'Accepter']);
        }
    
            $data->Etat_de_rdv = $request->changeStatus;

        }
        
     return redirect('/dashboard');    
}

这是表格:

   @if($lo->Etat_de_rdv == "en_attente") 
            <form action="{{ route('completedUpdate',$lo->id) }}" method="post">
                {{ csrf_field() }}  
                <input type="hidden" class="form-control"  name="id" value="{{$lo->id}}" >                        
                <button type="submit" class="btn btn-success" name="changeStatus" value="Accepter">Accepter</button>
            </form>                    
             @elseif($lo->Etat_de_rdv=="Accepter")
            <form action="{{ route('completedUpdate',$lo->id) }}" method="post">
                {{ csrf_field() }}  
                <input type="hidden" class="form-control"  name="id" value="{{$lo->id}}" >                            
                <button type="submit" class="btn btn-danger" name="changeStatus" value="Charger">Annuler</button>
            </form>                                                 
          @elseif($lo->Etat_de_rdv=="Pas disponible")
          <form action="{{ route('completedUpdate',$lo->id) }}" method="post">
              {{ csrf_field() }}  
              <input type="hidden" class="form-control"  name="id" value="{{$lo->id}}" >                            
              <button type="submit" class="btn btn-success" name="changeStatus" value="Accepter"> Accepter </button>
          </form>                                                 
        @endif

只需在查询中添加where条件即可。

DB::table('rdv')->where('id', $id)-> ...