Laravel
Beginner
1 min read
Blade Templating Basics
Example
{{-- resources/views/posts/index.blade.php --}}
@extends('layouts.app')
@section('title', 'All Posts')
@section('content')
<h1>Posts</h1>
@if($posts->isEmpty())
<p>No posts found.</p>
@else
@foreach($posts as $post)
<article class="{{ $loop->even ? 'bg-gray-50' : 'bg-white' }}">
<h2>
<a href="{{ route('posts.show', $post) }}">
{{ $post->title }}
</a>
</h2>
<p>By {{ $post->user->name }}</p>
<time>{{ $post->published_at->diffForHumans() }}</time>
@if($loop->last)
<hr class="mt-4">
@endif
</article>
@endforeach
{{ $posts->links() }}
@endif
@endsection
@push('scripts')
<script>console.log('Posts page loaded');</script>
@endpush
Related Resources
Laravel Reference
Complete tag & property list
Laravel How-To Guides
Step-by-step practical guides
Laravel Exercises
Practice what you've learned
More in Laravel