Using Laravel blade template, is there a way to include a variable and increase each time in the foreach or what is better approach?
For example:
@foreach($categories as $category) <li><a href="#tab_c1" role="tab" data-toggle="tab">{{$category->name}}</a></li> @endforeach
In the foreach
block, the value from #tab_c1 will need to be increase. eg: #tab_c1, #tab_c2, #tab_c3
In Laravel, @yield is principally used to define a section in a layout and is constantly used to get content from a child page unto a master page.
Remember that you'll have to define $i = 0 before the foreach loop if you want to start counting/incrementing from 0. Voting is disabled while the site is in read-only mode. Voting is disabled while the site is in read-only mode. Show activity on this post.
The Blade is a powerful templating engine in a Laravel framework. The blade allows to use the templating engine easily, and it makes the syntax writing very simple. The blade templating engine provides its own structure such as conditional statements and loops.
Add iterator to @foreach
:
@foreach($categories as $key => $category) <li @if ($key === 0) class="active" @endif> <a href="#tab_c{{$key+1}}" role="tab" data-toggle="tab"> {{$category->name}} </a> </li> @endforeach
{{$key+1}}
in my example because in PHP iterator starts at 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With