I have a view in which I have to execute foreach loops. The problem is that I want to get one input from first foreach then get the other input from the second foreach. I have an outer for loop which will execute until all the foreach is exhausted.
@for($i=0;$i<=$n;$i++)
<tr>
<th scope="row">{{$i}}</th>
@foreach($Names as $Name)&&
<td>{{$Name}}</td>
@endforeach
@foreach($users as $user)
<td>{{$user}}</td>
@endforeach
@endfor
try like this
@foreach($Names as $key => $val)&&
<td> {{$val}}</td>
<td> {{$users[$key]}} </td>
@endforeach
Your making a mistake with your structure here. You should have the Users and there names and username in one variable so you can foreach this result.
@foreach($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->user }}</td>
</tr>
@endforeach
If you want to add numbers to the list just add a counter with css or php if thats your way.
<?php $i=1; ?>
@foreach($users as $user)
<tr>
<td>{{ $i }}
<td>{{ $user->name }}</td>
<td>{{ $user->user }}</td>
</tr>
<?php $i++; ?>
@endforeach
thanks for trying guys. I got the answer...
@foreach($Names as $Name)
<tr>
<th scope="row">{{$i++}}</th>
{{--@foreach(@Names as $Name)--}}
<th> {{$Name}}</th>
@foreach($users as $user )
<td> {!! Form::text($users.$i,null, array('class' => 'form-control','id'=>$i)) !!} </td>
@endforeach
</tr>
@endforeach
The catch was that for loop and foreach required the same number of iterations. So we can simply eliminate for loop.