??? ???? ??????
??? ??? ???? ????? ??? ???? ? ??? ?? ??? ????. ??? ?? ??? ? ???? ???? ?????. HTML? ???? ???? ?? ???? ??? ???? ???? ???? ??? ?? ??? ?????.
????? ??????
Blade? Laravel? ?? ??? ????, ???? ?? ?? ???? ??????. ???? ???? resources/views ????? ???? ? ???? .blade.php ???? ????. ??? ???? ????? HTML? PHP? ?? ??? ? ????. ?:
<h1>Hello, {{ $name }}!</h1>
??? ????? ?? ??? ???? ?? ?? ????. ???? ?? ?? ? ??? ?? ??? ??? ?? ????. ?? ??? ????.
@if ($user)
<p>Welcome, {{ $user->name }}!</p>
@else
<p>Please log in.</p>
@endif
???? ??? ??? ?? ??? ???? ???? ?? ??? ??? ??? ???. ??? ??? ??? ???? ? ?? Blade? @foreach ???? ??? ????. ???? ??? ???? ?????.

??? ??
Blade? ?? ??? ?? ? ??? ????? ????? ? ??? ??? ????. ???? ?? ??? ???? ?? ?? ? ???? ??? ???? ??? ? ????. ??? ?? ??? ????.
<!-- layout.blade.php -->
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
<div>
<p>This layout has placeholders (@yield) for the title and the main content. Now, let’s say you’re creating a home page. You can extend this layout like this:<br>
</p>
<pre class="brush:php;toolbar:false">@extends('layout')
@section('title', 'Home Page')
@section('content')
<h1>Welcome to the Home Page!</h1>
@endsection
@extends? ???? ????? ???? @section? ???? ?? ???? ?????? ?? ? ????. ??? ?? ??? DRY(???? ??) ??? ???? ??? ??????. Blade? ?????? ????? ??? ? ?????? ????? ??? ?? ? ??? ? ??? ????.

???? ?? ??
???? ????? UI? ?? ?? ?? ??? ????. ?? ?? ????? ??? ???. ?????? ?? ??? ??? ??? ??? ??? ??? ???? ??? ? ????. ??? ?? ??? ? ???? ?? ??? ?????.
????? ? ? ???? ?????? ???? ??? ? ????. ?? ????? ???? ??? ??? ??????? ?? ?? ???? ?? ??? ??????! ? ??? ??? ????? ??? ???? ???? ?? ???? ?? ? ????.
??? ?? ?? ??? ??? ????.
<!-- resources/views/components/button.blade.php -->
<button>{{ $slot }}</button>
<!-- Usage -->
<x-button>Click Me</x-button>
???? ???? ???? ????? ???? ?? ? ????. ?? ?? ???? ???? ?? ??? ???? ??? ???? ???? ?? ??? ? ????.
// In a component class
public function render()
{
return view('components.button', [
'type' => $this->type,
'class' => $this->class,
]);
}
// In the Blade component
<button type="{{ $type }}">
<h2>
Including Subviews
</h2>
<p>Sometimes, you’ll want to break your templates into smaller pieces for better organization and reusability. Blade makes this easy with the @include directive. Think of it as a way to insert a smaller view (or subview) into a larger one.</p>
<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173172787698773.jpg" class="lazy" alt="Get The Most From Blade: Laravel&#s Templating Engine" /></p>
<h2>
Blade Directives
</h2>
<p>Blade comes packed with handy directives that make common tasks a breeze. Here are a few:<br>
@csrf: CSRF token to your forms, protecting them from cross-site request forgery attacks<br>
@method: specifies the HTTP method for forms<br>
@auth: checks if a user is authenticated<br>
@guest: checks if a user is a guest (not authenticated)<br>
</p>
<pre class="brush:php;toolbar:false"><form action="/submit" method="POST">
@csrf
@method('PUT')
<button type="submit">Submit</button>
</form>
? ? ???? ??? ??????? ??? ??? ??? ?? ?? ???? ???? ??? ? ????.
?? ?? ?? ??? ?? ???? ??? ??? ?????. ??? ?? ??? ?? ???? ??? ? ????.
<h1>Hello, {{ $name }}!</h1>

?? ??
Blade?? ?????? ?? ?? ???? ??? ?? ? ?? ?? ??? ??? ???? ????. ? ? ? ??? ???????.
?? URL ??
CSS ?? JavaScript ??? ???? ???? ??() ??? ??? ??????. ??? ?? ??? URL? ????? ??? ?? ??? ??? ????.
@if ($user)
<p>Welcome, {{ $user->name }}!</p>
@else
<p>Please log in.</p>
@endif
? ?? ?? ??? ??
Blade? @forelse ???? ? ???? ???? ??? ? ??? ?????. ??? ??? ? ?? ??? ?? ??? ???? ??? ? ????.
<!-- layout.blade.php -->
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
<div>
<p>This layout has placeholders (@yield) for the title and the main content. Now, let’s say you’re creating a home page. You can extend this layout like this:<br>
</p>
<pre class="brush:php;toolbar:false">@extends('layout')
@section('title', 'Home Page')
@section('content')
<h1>Welcome to the Home Page!</h1>
@endsection
??? ??? ??
Blade? ??? ?? ???? ???? ?? ?? ???? ?????.
@isset: ??? ?????? ??
@empty: ??? ?? ??? ??
@unless: if? ???? ????? ? ?????
@isset? ??? ?? ??? ????.
<!-- resources/views/components/button.blade.php -->
<button>{{ $slot }}</button>
<!-- Usage -->
<x-button>Click Me</x-button>
XSS??? ??
Blade? XSS(Cross-Site Scripting) ?????? ?? ???? ?? ??? ???? ????????. ??? ??? ?? HTML? ???? ?? ?? ????. ?? ?? {!! !!}:
// In a component class
public function render()
{
return view('components.button', [
'type' => $this->type,
'class' => $this->class,
]);
}
// In the Blade component
<button type="{{ $type }}">
<h2>
Including Subviews
</h2>
<p>Sometimes, you’ll want to break your templates into smaller pieces for better organization and reusability. Blade makes this easy with the @include directive. Think of it as a way to insert a smaller view (or subview) into a larger one.</p>
<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173172787698773.jpg" class="lazy" alt="Get The Most From Blade: Laravel&#s Templating Engine" /></p>
<h2>
Blade Directives
</h2>
<p>Blade comes packed with handy directives that make common tasks a breeze. Here are a few:<br>
@csrf: CSRF token to your forms, protecting them from cross-site request forgery attacks<br>
@method: specifies the HTTP method for forms<br>
@auth: checks if a user is authenticated<br>
@guest: checks if a user is a guest (not authenticated)<br>
</p>
<pre class="brush:php;toolbar:false"><form action="/submit" method="POST">
@csrf
@method('PUT')
<button type="submit">Submit</button>
</form>

?? ??
???? ??? ??? ?? HTML ?? JavaScript? ???? ???? Blade? ?? ??? ???? ?? ????? @verbatim ???? ??????.
// In a service provider
Blade::directive('datetime', function ($expression) {
return "<?php echo ($expression)->format('Y-m-d H:i:s'); ?>";
});
// Usage in Blade
@datetime($dateVariable)
API? ??????? Blade? ???? ????? ?? JSON ???? ?? ???? ? ????.
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
Livewire? ???? ?? Blade? ???? ?????. JavaScript? ?? ???? ??? ?? ??? UI? ?? Livewire ?? ??? ?? Blade ?? ??? ??? ? ????.
@once ???? ?? ??? ? ?? ????? ?????. Blade? ???? ???? ???? ???? ???? ?? ?? ??? ?? ? ????. ?? ???? ??? ??? UI ??? ?????.
@forelse ($items as $item)
<p>{{ $item }}</p>
@empty
<p>No items found.</p>
@endforelse
@error ???? ???? ?? ??? ?? ?? ???? ?? ??? ? ????.
@isset($variable)
<p>{{ $variable }}</p>
@endisset
?? Blade? ???? ???? ? ??? ??? ??? ?? ?????, ?? ??? ?? ? ??? ??? ?????. ??? ????? ?? ?? ???? ?? ??? ? ????. ? ??? ? ??? ??? ??? ?? ? ??? ???? ????.
? ??? Blade: Laravel? ??? ?? ??? ????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!