4
I have the following structure in a table in the database. My intention is that when I do a select * from
in it I can interact up the values so that I have an array in the hierarchical style.
That is, whenever there is an idFather, this value must be a child of a normal id that contains this value.
Example:
[ Id: 01, idFather: null, Name: "Galpão", Sub: [ Id: 02, idFather: 01, Name: "Bloco A, ] ]
UPDATED
This is basically my current code that mounts a single object without subcategories.
What I could do in it to achieve my goal?
public function getCategorias(CategoriaCollection $objCategorias){
$data = [];
foreach($objCategorias as $objCategoria){
$data[] = (object) [
'id' => $objCategoria->getId(),
'pai' => $objCategoria->getPai(),
'nome' => $objCategoria->getNome(),
];
}
parent::responderAjax(new AjaxResponse("", $data));
}
Any suggestions?
suggestion would be to use a recursive function or be called itself, so you can mount the pertendido array
– 13dev
I get it, but I’m having trouble imagining the logic for this recurse function, could you give me a hint? I updated the question with my current code. @13dev
– Matheus Nascimento