Answers for "how to get 2 foreach loop in laravel blade"

PHP
0

loop foreach laravel with number

@foreach($users as $index => $user)
  <td>{{ $index + 1 }}</td>
  <td>{{ $user->username }}</td>
@endforeach
Posted by: Guest on October-24-2021
1

Laravel foreach loop index in controller

//If you are working with a collection you can do something like this:
foreach($collection as $item) {
    if($collection->last() == $item) {
        // last iteration
    }
}

//If you are working with an array (it also works with collections) you can do this:
foreach($array as $item) {
    if(end($array) == $item) {
        // last iteration
    }
}
Posted by: Guest on June-11-2021

Code answers related to "how to get 2 foreach loop in laravel blade"

Browse Popular Code Answers by Language