is there any way to fetch iterate number in blades foreach loop over collection ? I'm going to use it for selected drop down input default value . (i don't want to use "form model binding")
i try thesis and they does not work, maybe cause thesis for getting index value in foreach loop over objects :
key($theArrayYouAreLoopingThrough)
{{ @index }}
@foreach ($athletes as $key=>$athlete)
{{ ++$key }}
@endforeach
and so on.
If you're using 5.3 you can use $loop
variable.
For example, to get current iteration, you can use inside @foreach
or @for
construction:
$loop->iteration
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