The main problem with Liam Wiltshire's answer is performance, because:
reset ($ items) rewind the collection pointer $ items over and over in every loop ... always with the same result.
Both are $ item , and the result of reset ($ item) is objects, so $ item == reset ($ elements) requires a complete comparison of its attributes ... requiring more processor time.
A more efficient and elegant way to do this, as Shannon suggests, is to use the Blade $ loop variable:
@foreach($items as $item) @if ($loop->first) First Item: @endif <h4>{{ $item->program_name }}</h4> @endforeach
If you want to apply a special format to the first element, perhaps you could do something like (using the ternary conditional operator ?:) :
@foreach($items as $item) <h4 {!! $loop->first ? 'class="special"': '' !!}>{{ $item->program_name }}</h4> @endforeach
Pay attention to the use of tags {!! and !!} instead of {{ }} to avoid encoding html double quotes around the special string.
Sincerely.
source share