I have the following structure in a table in the database. My intention is that when I make a select * from
on it I can interact with the values so that I have an array in the hierarchical style.
That is, whenever there is an idFather, this value must be the child of a normal id that contains that 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 assembles a single object without subcategories.
What could I 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?