Laravel - Bring SELECT SELECT type already selected when editing

-1

I am trying to bring a select already selected according to the information that is stored in the database. But I'm having a lot of trouble. I'll leave the code below.

Controller

public function ListaUf()
{
    $ListaUf = Estado::all();
    return view(‘psicologo’,compact(‘ListaUf’));
}

Routes

Route::get(’/psicologo/editar/{psi_codigo}’,‘ControladorMunicipioUf@ListaUf’);

View

<select>
    @foreach($ListaUf as $uf)  
        <option {{$psi->uf_codigo=={{$uf->uf_codigo}} ? 'selected':''}} value="{{$uf->uf_codigo}}">{{$uf->uf_estado}}</option>
    @endforeach
</select>
    
asked by anonymous 18.12.2018 / 20:32

1 answer

0

If you are looking for a specific state, use:

public function ListaUfEditar($id)
{   
   $ListaUf = Estado::find($id);
   return view('psicologo',compact('ListaUf'));

}

Or you can pass an array of ids to then return a collection.

To search for all states in a collection to iterate in your view, use the "all ()" method with no arguments.

link

    
18.12.2018 / 21:19