Laravel Blade Loop Variable With Check First and Last Record

10-Apr-2023

.

Admin

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...

#Laravel