Laravel Blade Loop Variable With Check First and Last Record




Hello Friends,

Laravel blade provide $loop variable inside loop. Using this variable you can check loop first,last record in if condition. you can check first and last iteration of loop. also using this variable you can check index,iteration,remaining,count,even,odd,depth,parent

Loop Variable Example

@foreach ($products as $product)

@if ($loop->first)

This is the first record.


@if ($loop->last)

This is the last record.


This is user {{ $product->id }}


I hope it can help you...