Problems when consulting the database with a Laravel drop-down list

0

I have a question. I have a forms with two fields one is a input and the other is a select when doing the search of the two fields does not bring me anything. Here I put my query:

$titulo = $request->get(‘titulo’);
$provincia = $request->get(‘provincia’);
$empleos = Empleo::orderBy(‘id’,‘DESC’) ->where(‘titulo’,‘LIKE’,"%$titulo%") ->where(‘provincia’, ‘LIKE’, “%$provincia%”) ->paginate(5);

Here my form:

{!! Form::open([‘route’ => ‘busquedaprincipal’, ‘method’=>‘GET’]) !!}
{!! Form::text(‘titulo’, null, [‘class’ => ‘form-control form-control-lg’, ‘placeholder’ => ‘Buscar’]); !!}
{!! Form::select(‘provincia’, [‘euskadi’ => ‘Euskadi’, ‘alava’ => ‘Alava’, ‘bizkaia’ => ‘Bizkaia’, ‘guipuzkoa’ => ‘Guipuzkoa’], null, [‘class’ => ‘custom-select form-control form-control-lg’, ‘placeholder’ => ‘¿Donde?’, ‘id’ => ‘provincia’]); !!}
{!! Form::submit(‘Buscar’, [‘class’ => ‘btn btn-primary btn-lg my-sm-3 boton border-0’]) !!}
{!! Form::close() !!}
    
asked by juan alejandro rivero 18.09.2018 в 20:07
source

1 answer

1

Try this:

First of all, print the variables to know if you are receiving the correct information, for that use:

dd($titulo,$provincia);

The correct way to receive the form elements in the controller is as follows:

$inputs = $request->input();
$titulo = $inputs['titulo'];
$provincia = $inputs['provincia'];

Already with these two clarifications, you should not give any inconvenience at the time of making the query.

Note: remember that the names with which you receive the inputs must be the same names of the elements of the form

$empleos = Empleo::orderBy('id','DESC')
->where('titulo','like','%'.$titulo.'%') 
->where('provincia','=', $provincia')
->get();
    
answered by 20.09.2018 в 19:56