
Laravel? ?? ? ??? ??: ???? ??? ?? ??? ????? ??
?? ? ???? ???? ?? ??? ?? ??? ?????? ??? ??? ???? ??? ??? ???? ? ?? ?????. ?? ???? PHP ?????? Laravel? ??? ?? ? ??? ?? ??? ????? ???? ??? ?? ??? ?????? ?? ???? ??? ? ????. ? ???? ???? ?? ??? ??? ?? ??? ???? ????, ???? ?? ? ? ???? ??? ? ??? ? ?? ?? ??? ?????.
1. ? ??
?? ???? ?? ? ?????? ?????? ??????. Laravel?? ? ??? resources/views ????? ?????. ?? ??? .blade.php ???? ??? ???? ??? ??? ???? ??????. ?? ??? ??? ??, ??? ?? ??, ??? ?? ? ?? ??? ?? ??? ?????.
2. ? ?? ? ???
? ?? ????? resources/views ????? ???? .blade.php? ? ??? ?????. ?? ??, ?? ??? ???? Welcome.blade.php?? ? ??? ?????:
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome to Laravel</h1>
</body>
</html>
? ?? ?????? ?????? ?? ??? ?????:
public function welcome()
{
return view('welcome');
}
?? ???? ? Laravel? ???? ??? ?? ?????. ??. ?? ??, ???? ??? ?? ???? ?? ??? ? ????:
public function welcome()
{
$data = [
'name' => 'John',
'age' => 30
];
return view('welcome', $data);
}
? ???? ??? ???? ?? ??? ??? ???? ???? ? ????:
<h2>Hello, {{ $name }}</h2>
<p>Your age is {{ $age }}</p>
3. ??? ?? ? ????
Laravel? ??? ?? Blade? ?? ???? ??? ??? ?????? ???? ?? ??? ??? ??? ?????. ??? ????? ???? ???? ?? ????.
???:
@if ($age > 18)
You are an adult.
@elseif ($age >= 13)
You are a teenager.
@else
You are a child.
@endif
?? ?:
@foreach ($users as $user)
<p>{{ $user->name }}</p>
@endforeach
- ?? ? ??:
@include('partials.header') ???? ??:
<title>@yield('title')</title>
<header>
@yield('header')
</header>
<main>
@yield('content')
</main>
<footer>
@yield('footer')
</footer>
?? ??? @section? ??? ? ??? @
@extends('layouts.app')
@section('title', 'Welcome')
@section('header')
<h1>Welcome to Laravel</h1>
@endsection
@section('content')
<p>This is the main content.</p>
@endsection
@section('footer')
<p>? 2021 Laravel</p>
@endsection
4. ?? ??? ? ??? ??
Laravel? ?? ??? ? ??? ?? ??? ????? ??? ? ???? ??? ?? ? ?? ??? ? ????.
?? ???:
with ? ?? ???? ???? ?? ?? ???? ??? ? ????.
public function index()
{
$data = 'Some data';
return view('view1')->with('data', $data);
}
??? ?? ???? ?? ???? ? ????. :
<p>{{ $data }}</p>
- ??? ??:
extends ???? ???? ?? ?? ????? ??? ?? @section ? @yield ???? ???? ?? ??? ?? ? ????.
5. ??
Laravel? ? ? ??? ?? ??? ????? ???? ??? ?? ??? ?????? ??? ? ?? ??? ??? ?????. ? ??? ?? ? ???? ???? ??? ??? ??? ?? ? ??? ?? ???? ??? ?? ??? ???? ?????? ?? ??? ? ????. ??? ?? ??? ? ??? ?? ??? ????? ??? ?? ? ?? ??? ?? ????? ????. Laravel? ?? ??? ??? ??????? ??? ??? ?? ??? ? ? ???? ? ??? ???? ??? ???? ? ????.
??? Laravel? ? ? ??? ??? ?? ?????. ???? ? ??? ???? ???? ? ??? ??? ????. ???? ?? ?? ??? ???? ? ?? ?????? ??? ??? ??? ? ?? ???? ????.
? ??? Laravel? ? ? ??? ??: ???? ??? ?? ??? ????? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!