1
I’m developing a route
for my api
, where it is intended to return a list of cities based on the fields and values of my array. Thus:
public function arrayCidades(Request $request)
{
$ay = $request->ay;
return $ay;
$result = Cidade::where($ay)->get();
return $result;
}
Keep going like I’m going through postman
, and the return it gives me of first question:
When commenting on the line return $ay;
, returns me the following error sql
:
"message": "SQLSTATE[HY093]: Invalid Parameter number: Parameter was not defined (SQL: select * from "cities" Where ("id_state" = 15 and "name_city" = 5))"
My goal here would be an sql like this:
select * from cidades where id_estado in(15,5) and nome_cidade = 'Santa Luzia'
Does anyone know how to solve?
Laravel 7.14.1
You want to pass the data that comes in the ARRAY format ... ? this has to be worked in the back-end, I did not understand which is your filter, is for all fields or is some in specific.
– novic
Missing say what you want !
– novic
The array name will always be by default
ay
. The name of your fields will always be some name that references the table, for exampleid_estado
andnome_cidade
.– Luiz Roberto Furtuna
Why do you want to do this? What type of filter you want to make, I think you have a better way to drive this filter
– novic
What are the filters? or do you want something dynamic? explain better
– novic
Filters are the names of the array fields, which refer to table fields
– Luiz Roberto Furtuna
only that you have duplicity in the fields because they are arrays ... what is the purpose?
– novic
There is duplicity because I want to pass more than one value to the same field understand? When passing
ay[id_estado]
anday[id_estado]
, Each one can assume only one value, right? Until then ok, my controller returns the data and quiet. But if I want to inform more of a different state, with anotherid_estado
for example, and use this in the search. This is my question: If there is how to do it this way, because for me it is already half way– Luiz Roberto Furtuna