Cleanup loops

Did you know the Blade @each directive can help cleanup loops in your templates?

1// good
2@foreach($item in $items)
3 <div>
4 <p>Name: {{ $item->name }}
5 <p>Price: {{ $item->price }}
6 </div>
7@endforeach
8 
9// better (HTML extracted into partial)
10@each('partials.item', $items, 'item')

Tip given by @kirschbaum_dev

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord