Reputation: 642
I have 5 foreach
s. So how do i increment i like
View
@foreach($questions as $question)
{{ $i }}
@endforeach
@foreach($inquiries as $question)
{{ $i }}
@endforeach
@foreach($queries as $question)
{{ $i }}
@endforeach
@foreach($examinations as $question)
{{ $i }}
@endforeach
@foreach($inquisitions as $question)
{{ $i }}
@endforeach
Upvotes: 1
Views: 2899
Reputation: 7111
You can use blade's variable dedicated to this:
@foreach($questions as $question)
{{ $loop->iteration }}
@endforeach
@foreach($inquiries as $question)
{{ $loop->iteration }}
@endforeach
@foreach($queries as $question)
{{ $loop->iteration }}
@endforeach
@foreach($examinations as $question)
{{ $loop->iteration }}
@endforeach
@foreach($inquisitions as $question)
{{ $loop->iteration }}
@endforeach
Upvotes: 2
Reputation: 710
if want your $i to change after every loop, you should be passing variable by reference.Check the article in the link below: link: http://php.net/manual/en/language.references.pass.php
Upvotes: 1
Reputation: 21681
You should try to below way.
<?php
$i = 0;
?>
@foreach($questions as $question)
{{ $i++ }}
@endforeach
@foreach($inquiries as $question)
{{ $i++ }}
@endforeach
@foreach($queries as $question)
{{ $i++ }}
@endforeach
@foreach($examinations as $question)
{{ $i++ }}
@endforeach
@foreach($inquisitions as $question)
{{ $i++ }}
@endforeach
Upvotes: 1
Reputation: 4040
@php
$i = 0;
@endphp
@foreach($questions as $question)
{{ $i }}
$i++;
@endforeach
use $i in each foreach loop as incremented $i++
Upvotes: 1