Laravel Blade Loop Variable With Check First and Last Record

Laravel

Nicesnippets

719

20-04-2020


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.

@endif

@if ($loop->last)

This is the last record.

@endif

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

@endforeach

I hope it can help you...