Problems with query where by means of select

2

Good morning

I have tried to make a filtered query, that is, in my view I select a name, after selecting it I give it to search and it should appear all the records related to that name.

in my view I have this:

link

In my controller I have this:

link

I can not send the data I want to the controller

    
asked by zereft 13.10.2018 в 22:05
source

2 answers

0

in your view

 <form action="{{action('[email protected]')}}" method="post">
                {{csrf_field()}}
                   <select name="tipo" id="tipo" class=" form-control"  value="{{ old('tipo') }}"  required>
                    @foreach($usuarios as  $usuario)
                      <option value="{{$usuario->usuario_ad }}">{{ $usuario->nombre }}</option>
                   @endforeach
               </select>
            <a class="btn btn-info" >Buscar</a>
         </form>

on your controller

$usuarios=usuarios::where("usuario_ad","=",$request->tipo)->get();
return  view('usuario.index',compact('usuarios'));

I hope it will help you or help you a bit in your logic

    
answered by 14.10.2018 / 02:26
source
0

Good tests with this, since you are launching a POST route you need to access the request variable.

<form action="{{action('[email protected]')}}" method="post">
  {{csrf_field()}}
  <select name="tipo" id="tipo" class=" form-control"  value="{{ old('tipo') }}"  required>
         @foreach($usuariosOpciones as $id => $usuario_ad)
         <option value="{{ $id }}">{{ $usuario_ad }}</option>
         @endforeach
  </select>
  <a class="btn btn-info" >Buscar</a>
 </form>

To access the value of the select, the select must be inside the "form" tags.

public function show(Request $request)
        {
            $usuarios=usuarios::where("usuario_ad","=",$request->usuario_ad)->get();
            $tipo = $request->tipo; //Para acceder a la variable del select
            return  view('usuario.index',compact('usuarios'));
        }
    
answered by 13.10.2018 в 23:29