mercredi 25 août 2021

problem with id does not show the correct and repeats

i have a problem with my online shift application

https://i.imgur.com/d1O5Eao.png

the user can view their shift requests. The problem is that clicking view (...) always redirects to shift ID 93 in the two registers

https://i.imgur.com/33hRcLa.png

Controller:

    public function inicio(){
    
        if (Auth::guest()) {
          return redirect()->route("login");
        }
    
        $config = Configuraciones::findOrFail(0);
       
       // Solicitudes = REQUEST 

        $solicitudes = Solicitudes::where('user_id', Auth::User()->id)->orderByDesc('created_at')->take(5)->get();

 GET THE ID OF THE REQUEST FROM THE LOGED USER
        $solicitud = Solicitudes::where('user_id', Auth::User()->id)->first();
    


// GET THE SHIFT 'id' RELATED TO THE 'id' OF THE request
        $eventos = Eventos::where('solicitud_id', $solicitud->id)->first();
       
       
        return view('solicitudes.inicio',compact('solicitudes','config','eventos'))->with($data);
       }

Blade: `

@foreach($solicitudes as $solicitud)
                                        @if(Auth::user()->id == $solicitud->user_id)
                                        <tr>
                                            <td></td>
                                            <td></td>
                                            <td class="text-center">
                                                @if($solicitud->estado == '0')
                                                <span class="badge badge-primary">Pendiente</span>
                                                @elseif($solicitud->estado == '1')
                                                <span class="badge badge-success">Aceptada</span>
                                                @elseif($solicitud->estado == '2')
                                                <span class="badge badge-danger">Rechazada</span>
                                                @endif
                                            </td>
                                            <td class="text-center">
                                                
                                                <div class="dropdown custom-dropdown">
                                                    <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-more-horizontal"><circle cx="12" cy="12" r="1"></circle><circle cx="19" cy="12" r="1"></circle><circle cx="5" cy="12" r="1"></circle></svg>
                                                    </a>

                                                    <div class="dropdown-menu" aria-labelledby="dropdownMenuLink1">
                                                        <a class="dropdown-item" href="/turno/">Ver</a>
                                                      
                                                    </div>
                                                </div>

                                            </td>
                                        </tr>
                                        @endif
                                        @endforeach`

Try using: $eventos = Eventos::where('solicitud_id', $solicitud->id)->get();

but it give error: Property [id] does not exist on this collection instance.

What can i do to get the correct shift ID? and that the same thing is not always repeated



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3Bc9I8r
via IFTTT

Aucun commentaire:

Enregistrer un commentaire