1
I have a select where I do a search from an informed id, No Postman do a POST by sending an array to as in the example below
[
{
"id":"1"
},
{
"id":"2"
}
]
In the repository I search for these id to get all the information about them.
how I would look in my repository at the time of doing the search and bring the information of the currently informed ids I do a simple search with a get();
Repository:
Public function listarId($id)
{
return $this->produto = DB::table('produtos')
->where('id', $id)
->get();
}
and send as a parameter in the Postman one id at a time
{
"id":"2"
}
in my controller it is as follows, I send request with the variable $id, and return to select that I did in Repository.
public function lista(Request $request)
{
$id = $request->input('id');
return $this->produtosRepository->listarId($id);
}
and I want to be able to send an array with several ids
In the sending controller I have a Request where I pass the id parameter to do this search, but it returns null, when I send it this way [ ː "id":"1" }, ? "id":"2" } ] has some way to get the information from this array to do the search
– Jess
the id you pass is generated here
$idP = $this->produtosRepository->lista($id);
?– Bulfaitelo
yes, in would have yes, however if I send as an array with more than two $id to do the database search, return null, but send only one {"id" : "5"} it normally recognizes
– Jess
Yes I have to understand how you take these values, when using Wherein you need to pass the simple array for example:
whereIn('id', [1,2,3]);
– Bulfaitelo
well I edited the question I think now gives to better understand
– Jess
in case the id array you will use in Where comes from that
lista()
? if yes runs a dd(); for me to see how this information is coming out, if not where this id’s from the search– Bulfaitelo
The id comes from this variable $idarray = $request->input('id'); which I pass as parameter here $this ->productsRepository->listarId($idarray ); when I send only one id, sure, but more than one ja returns null
– Jess
@Jessm rotates a
dd();
in this Return to understand better what is going on– Bulfaitelo
dd() ta returning [ ] empty
– Jess
if dd(); is returning null the problem is in the id’s, or better as you are getting them,
– Bulfaitelo
yes, when I command the Postman {"id":"1"} it returns the values correctly, but when I send [{"id":"1"},{"id":"2"}] it returns empty
– Jess
[{"id":"1"},{"id":"2"}] that you are commanding within the Wherein ? If it is ta manano a two-dimensional vector you have to pass only the ids, you will need to define which is passing the id
– Bulfaitelo