← Laravel tutorial

Laravel

Blade Templates

Blade templates (.blade.php files) mix HTML with {{ $variable }} to print a value (automatically escaped for safety) and @directives like @foreach and @if for logic.

Example: looping over posts in a template

{{-- resources/views/posts/index.blade.php --}}
<h1>Posts</h1>
<ul>
  @foreach ($posts as $post)
    <li>{{ $post->title }}</li>
  @endforeach
</ul>

Every @foreach needs a matching @endforeach, Blade directives always come in explicit start/end pairs rather than relying on indentation, which makes a template's structure unambiguous even in a long file. {{ }} escaping automatically happens by default specifically to prevent XSS, a value containing HTML/script tags gets displayed as harmless plain text instead of being executed, which is exactly the safe default you want for anything that ultimately came from user input.

Example
{{-- resources/views/posts/index.blade.php --}}
<h1>Posts</h1>
<ul>
  @foreach ($posts as $post)
    <li>{{ $post->title }}</li>
  @endforeach
</ul>
Output
Renders a bulleted list of every post's title.
Ready to go further?

These free tutorials are a preview, our Backend Development cohort covers it in depth, with a real project and a cohort alongside you. Active

Enroll in Backend Development
Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account