خانه درس‌ها
درس ۰۶ مبتدی ۱۱ دقیقه

قالب Blade

ساخت UI با سینتکس تمیز.

نمایش داده و حلقه

Blade
<h1>{{ $title }}</h1>

@foreach ($posts as $post)
  <article>
    <h2>{{ $post->title }}</h2>
    <p>{{ Str::limit($post->body, 100) }}</p>
  </article>
@empty
  <p>پستی نیست.</p>
@endforeach

Layout و بخش‌ها

layouts/app.blade.php
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
  <title>@yield('title', 'سایت من')</title>
</head>
<body>
  @include('partials.nav')
  @yield('content')
</body>
</html>
posts/index.blade.php
@extends('layouts.app')

@section('title', 'لیست پست‌ها')

@section('content')
  <h1>پست‌ها</h1>
  ...
@endsection

فرم و CSRF

Blade
<form method="POST" action="{{ route('posts.store') }}">
  @csrf
  <input type="text" name="title">
  <button type="submit">ذخیره</button>
</form>