-1
I am trying to assemble an array, but I am not getting, before the following table, I need to assemble the array as in the example below the photo.
6.x Standard design
in the'categoria_id 'columns which is null' are main categories. And the 'categorias_id with id, are the subcategories, with the id of the main category, I need something with this example that I set below.
$categorias = Categorias::orderBy('id', 'ASC')->get();
$categoria = $categorias->where('categoria_id', '=', null)->toArray();
$subcategoria = $categorias->where('categoria_id', '!=', null)->toArray();
I even separated, but I can’t put them together, as shown in the example below.
Array
(
[0] => Array
(
[id] => 1
[categoria] => Lanches
[categoria_id] =>
[status] => 0
[ordem] =>
[subcats] => Array
(
[3] => Array
(
[id] => 5
[categoria] => Lanches Tradicionais
[categoria_id] => 1
[status] => 0
[ordem] =>
)
[4] => Array
(
[id] => 6
[categoria] => Lanches Gourmet
[categoria_id] => 1
[status] => 0
[ordem] =>
)
[5] => Array
(
[id] => 7
[categoria] => Lanches Caseiros
[categoria_id] => 1
[status] => 0
[ordem] =>
)
)
)
[1] => Array
(
[id] => 2
[categoria] => Porções
[categoria_id] =>
[status] => 0
[ordem] =>
)
[2] => Array
(
[id] => 4
[categoria] => Sucos
[categoria_id] =>
[status] => 0
[ordem] =>
)
)
I’ve tried to ride in various ways, but no success, I don’t know what else to do.
you receive this information from the database in raw format?
– novic
yes, in Laravel.. return all categories..
– MichaelCosta
updated the question, give a look
– MichaelCosta
I made the answer and option 2 better solves your problem, take a look!
– novic
top bro! I had to leave, I arrived now I will test, but face I imagine it will solve, I already answer you
– MichaelCosta