Skip to content
Advertisement

Blade Recursive, increase the depth for padding

I want to increase the depth int each time children are in a item so I can pad out the a tag.

Below is my code and I assumed this would work, however the number stays at 1 even though I have got children within my one of the items within $items.

sidebar.blade.php

JavaScript

sidebar.items.blade.php

JavaScript

SidebarItems.php

JavaScript

Data:

JavaScript

Result:

JavaScript

Advertisement

Answer

If I get it right what you want to achieve, you don’t even need the $depth property, since the blade’s @foreach directive has its own depth property which tells you how nested you are.

In your code, instead using:

JavaScript

use:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement