1//If you are working with a collection you can do something like this:
2foreach($collection as $item) {
3 if($collection->last() == $item) {
4 // last iteration
5 }
6}
7
8//If you are working with an array (it also works with collections) you can do this:
9foreach($array as $item) {
10 if(end($array) == $item) {
11 // last iteration
12 }
13}